This should be simple but I can not get the "if ($result === FALSE)" in the below code to work when no matching records are found. It works just fine if records are found but does not work if no records are found. Can someone point out what I doing wrong?
Thank you Kevin.
$SQL = "SELECT * FROM Master WHERE (Title like '%".$SeachFor."%') or (Keywords like '%".$SeachFor."%') ORDER BY Title" ;
$result = mysqli_query($GLOBALS["connection"], $SQL);
if ($result === FALSE) {
echo 'No results found';
} else {
$num_rows = mysqli_num_rows($result);
$Counter = 1;
$DisplayedCounter = 1;
?>
<?php require_once('displayproduct.php'); ?>
<?php
}
?>
You could add a || mysql_num_rows() == 0
to your if statement, but something like this would be more ideal.
if($result === false) {
trigger_error(mysqli_error($GLOBALS['connection']));
} else if(mysqli_num_rows($result) === 0){
echo 'No results found';
} else {
$Counter = 1;
$DisplayedCounter = 1;
}
This will allow you to see if there are any errors with the SQL query. mysqli_query()
only returns false as a boolean upon failure. Otherwise you need to check mysqli_num_rows();