如何从mysql_num_rows返回空行?

时间:2012-06-04 19:19:28

标签: php mysql json

我有以下mysql查询以JSON方式返回数据。什么是检查是否有0条记录并返回该事实的最佳方法?

$row_num = mysql_num_rows($rslt);
$data = array();
while ( $row = mysql_fetch_row($result) )
{
    $data[] = $row;     
}   
echo json_encode( $data );

1 个答案:

答案 0 :(得分:0)

$row_num = mysql_num_rows($rslt);
$data = array();
while ( $row = mysql_fetch_row($result) )
{
    $data[] = $row;     
}   
if(!$data){
   echo "This is the government. We have removed your database!";
} else {
    echo json_encode( $data );
}