Checking if mysql_query returned anything or not

mysql, php, sql

Solution

You could use mysql_num_rows($results) to check if 0 rows were returned, or use this faster alternative:

$query = "SELECT COUNT(*) AS total FROM table";
$results = mysql_query($query, $connection);
$values = mysql_fetch_assoc($results);
$num_rows = $values['total'];

Problem

``` $query = "SELECT * FROM `table`"; $results = mysql_query($query, $connection); ``` If 'table' has no rows. whats the easiest way to check for this.?

Original source