如何显示找不到任何结果的错误消息
问题描述:
如何让PHP显示一条消息,指出它找不到任何结果,而不是在查询找不到任何结果时显示任何结果结果如何?如何显示找不到任何结果的错误消息
这里是我的代码结果的显示:
print " <table border = '1'> \n";
print " <tr> \n";
while ($field = mysqli_fetch_field($result)){
print " <th>$field->name</th> \n";
} // end while
print " </tr> \n";
while ($row = mysqli_fetch_assoc($result)){
print " <tr> \n";
foreach ($row as $name => $value){
print " <td>$value</td> \n";
} // end foreach
print " </tr> \n";
} // end while loop
print " </table> \n";
答
通过mysqli_num_rows(),你可以指望具有表中数据的行数。
$row_cnt = mysqli_num_rows($result);
if($row_cnt > 0){
//data exist for it
}else{
//Display your error message here
}
+0
谢谢你,很抱歉的坏研究我做到了。如果你愿意,你可以关闭它。 – 2014-10-01 22:23:03
+0
+1(你接受你的错误.. :) – 2014-10-03 07:55:32
http://php.net/manual/en/mysqli-result.num-rows.php – CBroe 2014-10-01 13:42:38