June 17th, 2000, 08:15 PM
Hello.. I'm Portuguese... and i start with PHP recently...
Can you help me... I have a search engine which works with MySQL...
How can i search with two or more words...
Search: music rock
And the results are : everything wich contains the words music and/or rock
Thanks Very Much
June 17th, 2000, 11:40 PM
select * from table_name where search_field like '%$first_term%' or search_field like '%$second_term%'
June 18th, 2000, 12:00 AM
$query = "music rock";
#you could split these using explode()
$splitquery = explode(" ",$query); //split where there is a space
$number = count($splitquery); //count the number of elements splitted to
#beginning of database query
$q1= "select * from $urls_table where ";
#second part of query
$i = 0;
while ($i<$number) //while there are still array elements to go
$q1 .= "field LIKE '%$splitquery[$i]%' OR ";
$i++; //increment $i
#remove the extra " OR" from the end
$q1 = substr($q1,0,-3);
echo "$q1"; //just so u can see it works
this one took me a little while...works for me so should work for you
[This message has been edited by 'tantrum (edited June 17, 2000).]