I was just wondering if there is the best way of doing this query?
$searchTerm = explode(' ', $search);
$wall_sql = "SELECT filename, category, name, downloads FROM wallpapers WHERE (pending='0' AND mediaType='0') AND ( ";
for($i=0;$i<count($searchTerm);$i++){
if($i != 0){
$wall_sql .= " OR ";
}
$wall_sql .= " (category LIKE '%".$searchTerm[$i]."%') OR (filename LIKE '%".$searchTerm[$i]."%') OR (tags LIKE '%".$searchTerm[$i]."%') OR (name LIKE '%".$searchTerm[$i]."%') ";
}
$wall_sql .= " ) ORDER BY ordernum DESC ";
What this script does it it takes in a search term $search and splits it into an array using the explode function in PHP. I then loop on that array to build up the query. This is the only way I can think to do it, I'm just not sure it's the best way of doing it. Also would any indexes work on this query if so what would they be?