How to check the elements?

function filter($twig,$filterName,$filter){
 $items = mysql_query("SELECT * FROM `items` WHERE {$filterName} = '{$filter}'");

 while ($row = mysql_fetch_array($items)){
 $list[] = $row;
};
 echo $twig->render('list.html', array('items' => $list));
}


tried so
if(!mysql_fetch_array($items)){
 echo $twig->render('404.html');
exit;
 }


but everything breaks down, the first item is not displayed.
March 23rd 20 at 19:23
1 answer
March 23rd 20 at 19:25
Solution
function filter($twig,$filterName,$filter){
 $items = mysql_query("SELECT * FROM `items` WHERE {$filterName} = '{$filter}'");
 $list = []; // create an empty
 while ($row = mysql_fetch_array($items)){
 $list[] = $row;
};
 if (!empty($list)) {
 echo $twig->render('list.html', ['items' => $list]);
 } else {
 echo "Ahhh-Ah-Ah-Ah-Ah!!!!!11 All is lost!";
}
}

Find more questions by tags PHP