如果查询中没有返回任何内容,如何显示消息?我试过这个:
while($info2 = mysql_fetch_assoc( $data2 ))
{
// la la la lots of code here
}
else
{
echo "Nothing Returned";
}只为了得到这个错误:
解析错误:语法错误,意外的T_ELSE
谢谢大家的帮助!
发布于 2012-03-20 22:25:51
类似于:
if(mysql_num_rows($data2) > 0){
//while loop goes here
} else {
//echo message
} 发布于 2012-03-20 22:24:57
使用mysql_num_rows检查查询返回的行数
if(mysql_num_rows($data2) > 0)
{
while($info2 = mysql_fetch_assoc( $data2 ))
{
///la la la lot's of code here
}
}
else
{
echo "Nothing Returned";
}发布于 2012-03-20 22:25:26
一个简单的PHP函数:
if (mysql_num_rows($data2) != 0)
{
// your while
}
else
{
// if nothing
}此函数只计算返回了多少行。
https://stackoverflow.com/questions/9795924
复制相似问题