Looping from address bar

I have a search engine code that requires a search on a variable submitted by the user which generates in the address bar

EG. http://mywebsite.com/results.php?search=My+Lovely+Horse

“My Lovely Horse” having been what the user entered on a previous form

I am using this code:

$search = $_GET[‘search’];

and then using LIKE in the query to search my database for corresponding. HOwever, this only works for the first word “My.”

What kind of loop could i create around the above statement to ask it to search for any other words (“Lovely”, “Horse”) to return the result in full?

Does any of that make any sense?

You could use $_SERVER[‘QUERY_STRING’] which would return EVERYTHING after the ? and then parse that.

Anyway, I think the problem you might be encountering is what you are passing and how it’s being put in the query string.

could u post the sql code u are using?

searching is a little more complicated. there is a feature of mysql called full text index/search. but u may as well use something like spitting up the words and use like:
[php]
$search = explode(’ ',$_GET[‘search’]);
$sql= ‘SELECT * FROM xxx WHERE ‘;
foreach( $search as $word)
{
$sql.= ’xxx LIKE "%’.mysql_escape_string($word).’%" OR ';
}
$sql.= ‘0’;
[/php]

but to have a good working search u have to do that with all fields and have to think about word parts, multible blanks, special chars and some more.

Sponsor our Newsletter | Privacy Policy | Terms of Service