询问是否在PHP中使用mysql_num_rows的正确方法 [英] Proper way to ask if mysql_num_rows in PHP
本文介绍了询问是否在PHP中使用mysql_num_rows的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因为mysql_num_rows如果没有返回行,则返回false,所以最好这样做:
Because mysql_num_rows returns false if there are no rows returned, would it be best to do:
$query = mysql_query("SELECT id FROM table WHERE something = 'this'");
$result = mysql_num_rows($query);
if ($result) { }
或者我应该这样做:
if ($result >= 1) { }
推荐答案
合适的
$result = mysql_query("SELECT id FROM table WHERE something = 'this'");
if (mysql_num_rows($result)){
//there are results
}
但是,您无需检查即可更轻松地完成此操作
however, you could do this easier, without checking
$result = mysql_query("SELECT id FROM table WHERE something = 'this'");
while($row = mysql_fetch_assoc($result))
//there are results
}
请.给变量起个合适的名字
Please. Give your variables proper names
这篇关于询问是否在PHP中使用mysql_num_rows的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文