如果我的查询没有返回任何内容,如何显示消息? 我尝试这样做:如果查询没有返回,则显示消息
while($info2 = mysql_fetch_assoc($data2))
{
// la la la lots of code here
}
else
{
echo "Nothing Returned";
}
只有得到这个错误:
Parse error: syntax error, unexpected T_ELSE
感谢您的帮助大家!
如果我的查询没有返回任何内容,如何显示消息? 我尝试这样做:如果查询没有返回,则显示消息
while($info2 = mysql_fetch_assoc($data2))
{
// la la la lots of code here
}
else
{
echo "Nothing Returned";
}
只有得到这个错误:
Parse error: syntax error, unexpected T_ELSE
感谢您的帮助大家!
喜欢的东西:
if(mysql_num_rows($data2) > 0){
//while loop goes here
} else {
//echo message
}
没关系,它的工作原理! – pufAmuf 2012-03-20 22:41:20
使用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";
}
非常感谢Teez! – pufAmuf 2012-03-20 22:42:50
一个简单的PHP函数的行数:
if (mysql_num_rows($data2) != 0)
{
// your while
}
else
{
// if nothing
}
此功能只算多少行返回。
认为你有你的意见逆转... :-) – keithhatfield 2012-03-20 22:26:54
@dleiftah在清楚? – 2012-03-20 22:29:16
你显示while循环在'num_rows == 0'的地方出现,实际上,错误信息应该出现在'num_rows == 0'的地方...... – keithhatfield 2012-03-20 22:30:43
else语句只能跟着一个if语句之后。你还应该检查affected_rows
请阅读[手册](http://php.net/manual/en/control-structures.while.php)。在任何编程语言中都没有'while' /'else'语法。像这样的问题只是令人尴尬。 – Jon 2012-03-20 22:24:59
我通过在MySQL论坛上的谷歌搜索找到了这个。 – pufAmuf 2012-03-20 22:27:44