I have created a php function thats meant to return a sql query which I can use to perform a simple search from mysql and show results to the end user
When I submit the form using the function I get this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean
FORM PHP
$dbc=mysqli_connect(DB_HOST,DB_USER,DB_PW,DB_NAME);
$user_search=$_GET[‘searching’];
$query=build_query($user_search);
$result=mysqli_query($dbc,$query);
//loop through the results
while ($row=mysqli_fetch_array($result)){
echo ‘<table><tr><td>’.$row[‘deal_name’].‘</tr></td></table>’;
}
PHP FUNCTION
function build_query($user_search) {
$search_query= "SELECT * FROM deals";
//get the search keywords
$clean_search=str_replace(',',' ',$user_search);
$search_words=explode(' ',$clean_search);
$final_search_words=array();
if(count($search_words>0)){
foreach($search_words as $word) {
if(!empty($word)){
$final_search_words[]=$words;
}
}
}
//generate a where clause with the search terms above
$where_list=array();
if(count($final_search_words)>0){
foreach($final_search_words as $word) {
$where_list[] ="deal_name LIKE'%$word%'";
}
}
$where_clause=implode('OR',$where_list);
//add keyword WHERE clause to the search query
if (!empty($where_clause)){
$search_query.="WHERE $where_clause";
}
return $search_query;
}