I want to do searching for data using users' entry in a field. That is if user enters "D+t+y+g,k,j,h" want to search for values having letters "d and t and y and g or k or j or h". I tried the PHP str_replace
function, but didn't like the result.
//kw is text field...
if($kw != "") {
//here we check for some data in field; if yes, continue below
//c is for ',' replaced in JavaScript
$kw1 = str_replace("c"," OR bcm.keywords LIKE '$kw%' ",$kw);
//p is for '+' replaced in JavaScript//'bcm' is table name.
$kw3 = str_replace("p"," AND bcm.keywords LIKE '$kw%' ",$kw1);
//for appending into main query string
$app.=$kw3;
//$app.=" AND bcm.keywords LIKE '$kw%'";
}
...but for the input "D+t+y+g,k,j,h" the query is coming out like this:
AND bcm.keywords LIKE 'Dptpypgckcjch%' t
AND bcm.keywords LIKE 'Dptpypgckcjch%' y
AND bcm.keywords LIKE 'Dptpypgckcjch%' g
OR bcm.keywords LIKE 'D
AND bcm.keywords LIKE 'Dptpypgckcjch%' t
AND bcm.keywords LIKE 'Dptpypgckcjch%' y
AND bcm.keywords LIKE 'Dptpypgckcjch%' gckcjch%' k
OR bcm.keywords LIKE 'D
AND bcm.keywords LIKE 'Dptpypgckcjch%' t
AND bcm.keywords LIKE 'Dptpypgckcjch%' y
AND bcm.keywords LIKE 'Dptpypgckcjch%' gckcjch%' j
OR bcm.keywords LIKE 'D
AND bcm.keywords LIKE 'Dptpypgckcjch%' t
AND bcm.keywords LIKE 'Dptpypgckcjch%' y
AND bcm.keywords LIKE 'Dptpypgckcjch%' gckcjch%' h**
...when what I want/need is:
AND bcm.keywords LIKE 'D%'
AND bcm.keywords LIKE 't%'
AND bcm.keywords LIKE 'y%'
AND bcm.keywords LIKE 'g%'
OR bcm.keywords LIKE 'k%'
OR bcm.keywords LIKE 'j%'
OR bcm.keywords LIKE 'h%'