Monday, May 7, 2012

Test if mysql query returns no results in PHP




 Run MySQL query script to see if the query returns no results using mysql_num_rows function in PHP.
PHP Code:
<?php
global $db;
$sql = "SELECT event_id FROM cesei_activity"
 $result = mysql_query($sql, $db);
 if(mysql_num_rows($result)!=0){
           echo 'Number of rows returned = '.mysql_num_rows($result);
 } else{
            echo "No row returned";
}
?>      

No comments:

Post a Comment