我在PHP有這個疑問:mysql_num_rows()給出了一個布爾值
<?php
$comments_list = mysql_query("SELECT * FROM comments ORDER BY `date` DESC, `time` DESC LIMIT 5");
echo mysql_error();
if (mysql_num_rows($comments_list) != 0)
{
echo('<ul>');
while ($comment = mysql_fetch_array($comments_list))
{
echo('<li>'.substr($comment['content'],0,70).'</li>');
}
echo('</ul>');
}
else
{
echo('<center>No comment.</center>');
}
?>
如果我的表是空的就給出了這樣的錯誤:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.9\www\admin\index.php on line 101
編輯:我是在ORDER BY
之前查詢LIMIT 5
。現在它已經修復了,我添加了在問題中編輯的echo mysql_error()
。
-1沒有閱讀文檔。 http://php.net/function.mysql-query.php – 2012-02-04 19:01:25
至於修復你的SQL查詢,把LIMIT子句__after__放在ORDER BY子句中 – 2012-02-04 19:03:34