I am creating a search within my database and when I used the foreach construct for my results to be echoed I'm getting "invalid argument being supplied for foreach..". What I don't understand is why this error is coming up because the foreach containing my errors works fine.
if (empty($errors)){
$results = search_results($keywords);
$results_num = count($results);
foreach ($results as $result){
echo '<p> <strong>', $result['TITLE'], '</strong> </p>';
}
} else {
foreach($errors as $error){
echo $error, '</br>';
}
}
The part of the search_results function that's being focused on is this
$results = "SELECT TITLE FROM occupationalinfo WHERE $where";
$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results): 0;
if ($results_num === 0){
return false;
}else{
while ($results_row = mysql_fetch_assoc($results)) {
$returned_results[] = array(
'title' => $results_row['TITLE']
);
}
}
I am still new to programming so I understand if there is something I may have missed or just not quite get. I would greatly appreciate any tips or constructive criticism.