PHP MySQL Clause IN() with array
Posted: Thu Dec 23, 2010 1:15 pm
Hi all,
I am trying to make my site search easier for usrs to find what they want.
at the moment I am using "%LIKE% clause" it works ok but I have noticed that if people search for something like "mountain bikes" it will not retunr a item which contains bikes which I would like it to do.
I did change my code to
but I am not getting any results becuase it is not looking through the array of $q and is simply searching using $q[0]
Is there an efficient way to achieve what I want?
Thanks in advance.
Just had a thought.
I am thinking maybe if I build a query of %LIKE%'s OR etc this would work.
Any suggestions?
I am trying to make my site search easier for usrs to find what they want.
at the moment I am using "%LIKE% clause" it works ok but I have noticed that if people search for something like "mountain bikes" it will not retunr a item which contains bikes which I would like it to do.
I did change my code to
Code: Select all
$q = explode($_REQUEST['q']);
//and in my query i used the IN($q) clause instead of %LIKE%
Is there an efficient way to achieve what I want?
Thanks in advance.
Just had a thought.
I am thinking maybe if I build a query of %LIKE%'s OR etc this would work.
Code: Select all
$like_q = '';
foreach($q as $k=>$v){
$like_q .= ' OR LIKE $v ';
}//