hiya I am using php to search a table in a mysql db. Am having a problem though and am really stuck 🙁
I want to search 2 different fields from multiple words entered in a search field on a form and return unique results. This is my current code to perform this task:
$searchstring = explode(" ",$keywords);
for ($k=0; $k < count($searchstring); $k++) {
$sql5 = "SELECT DISTINCT * FROM table where status = '$status' AND title like '%$searchstring[$k]%' or description like '%$searchstring[$k]%' and status = '$status' ORDER BY enddate ASC LIMIT $start1,$maxperpage";
$sql_result = mysql_query($sql5,$cid)
or die("Couldn't execute query.");
$result5=mysql_query($sql5,$cid);
}
This almost does what I want it to do but... If only one keyword is entered then everything is fine, if 2 keywords are entered and the 2nd keyword is not found in the fields then no results are returned. If both 1st and 2nd keywords are found in the fields then it returns only the results from the 2nd keyword. If 2 keywords are entered and the first keyword is not found everything is fine too.
I really dont know wher I am goin wrong, my query statement makes perfect sense to me but it's as if mysql is looking at the 'OR' and saying choose one or the other but not both ?? ANy help with this would be so greatly appreciated.
Thanks.