A simple search Mysql Query I need
I HAVE A TABLE WITH BUSINESS NAMES
THE ICE AGE
THE PIT STOP
CUTE CUT THE SALOON
THE LEGEND HOTELS & RESORTS
THE GATEWAY HOTEL
I want my search like this,
If I type in the search let us say " Pit" , I should get the Business Name THE PIT STOP
If I type in the search let us say " The" , I should get the Business Name THE ICE AGE. THE PIT STOP, CUTE CUT THE SALON, THE LEGEND HOTELS & RESORTS, THE GATEWAY HOTEL
If I type in the search let us say " Tel" (which is a part of Hotel) , I should NOT get any results
Can anyone help me with the mysql search query please.
|Start from here. |
Keyword Search from MySQL
From this many improvements can be added
|Thanks! I tried many options but could not get,|
Select * from Business where BusinessName like '%$SearchKeyword%' order by Businessid DESC";
Can someone help to give me the Command Statement.
|Your statement is correct only. Any error message you are getting. Start from this basic like command and then go to advance search using Like command|
|I am not getting any error message but the search result is not what I am looking for|
if I type 'ote' in say a word like 'hotel' i should not get any results, but i get all results where ever the word contains ote that is middle of a word, which is not right.
I wish you can give me the code than give me links
|You can restrict that by adding a space before the word 'ote'. As you are searching for records which has word starting with 'ote' so there is always a space before the 'ote' , so your query should be like this . |
select * from business where businessName like '% $SearchKeyword%' order by Businessid DESC
Watch the space between % and $SearchKeyword. That will filter the matching records which has words starting with 'ote'.
|Well firstly thanks for all the help,|
you are not getting me what I said earlier, let me explain further
When I type Hotel I get the results like this
1 HOTEL INDU RESIDENCY
2 HOTEL VISHNU RESIDENCY A/C -- -- --THE LODGE
3 HOTEL MORYA
4 HOTEL KARANTHS'
5 HOTEL MEGHALAYA
6 HOTEL SRI SAI DHABA
7 THE LEGEND HOTELS & RESORTS
8 THE GATEWAY HOTEL
9 DOLPHIN HOTELS LIMITED
10 ROYAL FORT HOTEL
But when I type 'ote' which is in the middle of the word 'hotel' I should not get any results, because the word ote is in the middle of the word hotel, yes any words starting with ote will be displayed.
I hope I am clear.
Thanks once again
|In this case you will have space in both side of ' ote ' . So when you type ote it won't pick up hotel. |
You can also add AND OR combination inside the query. For example along with the above query you can add one OR combination to the same query
WHERE businessname like '% $keyword %' OR businessname like '$keyword %'
This way you will include the words where ote is at the starting.
|Thanks for all your help, I could finally crack the problem by using Regexp|
where REGEXP '[[:<:]]$SearchKeyword'
This has solved the problem, but I will try your examples for further knowledge.
Thanks once again for all your help.
Maybe this time you can help me with Autocomplet of Search Box which should work well both in IE and Mozilla Firefox