I\'m looking for the best way to check and see if any results were returned in a query. I feel like I write this part of code a lot and sometimes I get errors, and sometimes
One way to do it is to check what mysql_num_rows returns. A minimal complete example would be the following:
if ($result = mysql_query($sql) && mysql_num_rows($result) > 0) {
// there are results in $result
} else {
// no results
}
But it's recommended that you check the return value of mysql_query and handle it properly in the case it's false
(which would be caused by an error); probably by also calling mysql_error and logging the error somewhere.