Checking MySQL result (PHP)

by spyka (http://www.spyka.net)

Use the below code to make check at least one row was returned from a MySQL query.

Code:
<?
$sql
=mysql_query("SELECT `foo` FROM `bar`"); // Perform query
if(mysql_num_rows($sql)!=0) { // Check how many rows were returned
    // Do whatever you want
} else {
    echo 
"No rows were returned!";
}
?>

Code demo

Not available

Help and comments

Discuss this and other scripts in our webmaster foruns

Learn more about our forums