在mysql,php中未选择任何行时,如何显示消息? [英] How can I show a message when no rows have been selected in mysql, php?

查看:53
本文介绍了在mysql,php中未选择任何行时,如何显示消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

$result = mysql_query("SELECT * FROM `picdb` WHERE `picid` = '$picid' ") or trigger_error(mysql_error()); 
while($row = mysql_fetch_array($result)){ 
foreach($row AS $key => $value) { $row[$key] = stripslashes($value); } 

问题是,当没有行可供选择时,什么也没发生,我的$ row数组为空.

Problem is that when there is no row to select, nothing happens, my $row array is empty.

当没有与选择匹配的行时,如何显示找不到行"的消息?

How can i have this present a message of "no row found" when no rows match the select?

推荐答案

尝试

if (mysql_num_rows($result) == 0) {
  // Show message
} else {
  // do your while stuff here
}

这篇关于在mysql,php中未选择任何行时,如何显示消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆