我有以下mysql查询以JSON方式返回数据。什么是检查是否有0条记录并返回该事实的最佳方法?
$row_num = mysql_num_rows($rslt);
$data = array();
while ( $row = mysql_fetch_row($result) )
{
$data[] = $row;
}
echo json_encode( $data );
答案 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 );
}