![]() |
Multi word search?
How can you setup you web seach to do a multi word like search?
I have a search on my site now that I put in.. it works great if you put in one word and spell it correct... but if you do not spell it right or have more that one word... your results are 0... if they have multi words and they are spelt correct and the way I have them in the table they will show... What can I do about this problem.. Thanks.. Slayer. |
Can't do anything about spelling mistakes. Too bad for the stupid user.
But suppose the search is for "ocean resort" You might do something like: Code:
SELECT * FROM table WHERE somefield LIKE '%ocean%' OR somefield LIKE '%resort%'Since you are showing NONE of your current code, I can't change non-existent code for you. |
This is what I currently have..
PHP Code:
I would search for New Old Town and it would give me 0 results. if I just search town I get 15 results if I search just old I get 20 results and if I search for new I get 7 results. Not sure what I have done wrong. Thanks... all help appreciated. Slayer. |
ONE more time:
You *MUST* split up the $find into SEPARATE WORDS and use LIKE on *EACH* word! So if $find is "New Old Town" your query would need to be: Code:
SELECT * FROM campgrounds If finding *ANY* ONE of the words in any of the fields is good enough, then replace all the AND with OR instead. |
how can you split up the words? and then search all the fields?
Sorry... Slayer. |
I don't use PHP.
I'll give it a try, but don't be surprised if I mess up the PHP code. Code:
<?php |
Hey Old Pedant..
this is working.... sort of whe I search still for one word... works great... when I search for multi... I get this error.. I echoing the search so see what it looks like to.. Quote:
Quote:
|
I changed it to "OR"
Quote:
You are awesome... thank you!! sooooooo much!!! P.S. your php was just fine.... I got it worked out... Slayer. |
Quote:
In my code $sql is nothing but a string. That looks like you echoed the $result. And if the OR version worked, the AND version should work, too. But only if you actually had some data that matched the condition! In the $pattern that you showed: Code:
## LIKE '%new%' AND ## LIKE '%old%'As I said, it depends on what you want. |
you are correct Old Pedant,
It was from my code.. I was echoing that info to see what the output was gonna be.. I tested it using "And" too and you are right there as well.. All works great.. I wish I asked this question a year ago... Thanks again for everything. Slayer. |
You know, you COULD offer you users the choice of "Find matches on any words" vs. "Find matches on all words".
Do something like this: Code:
<label>Code:
$delimiter = $_POST["delimiter"]; |
That is a great idea.... I will have to implement that to the website.
Thanks again for everything. Slayer. |
| All times are GMT +1. The time now is 07:45 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.