How to check mysql results are empty or not. if mysql query results are empty then else condtion should not be excueted. In case mysql results data there & in else condition my error my message are there but it is not showing any error message. I have tried following code but not showing any alert or echo message on screen.
<?php
$sql = "select * from hall_search_data_1 where rent BETWEEN '".$_SESSION['amount1']."' AND '".$_SESSION['amount2']."'";
$res = mysql_query($sql);
if(!empty($res)){
while($row=mysql_fetch_row($res))
{
// here my data
}
}else{
echo "no results found";
echo "<br>";
echo "<script>alert('No any result found..!!');</script>";
echo "no results found";
}
?>
For your answer you have to only check
no of rows
is zero or not Read this Post at php documentation with Example.mysqli_num_rows
Check number of rows
You can use mysql_num_rows to get count of number of rows returned from query.
Note: mysql is deprecated instead use mysqli or PDO as seen above
You can use mysql_num_rows to check the number of your result set:
Find here the documentation of mysql_num_rows:
mysql_num_rows
You can use
mysql_num_rows();
to check your query return rows or not