我正在开发自己的论坛,除了我尝试按日期时间排序之外,一切都运行良好。我的表名是正确的,所有的字段名也是正确的!当我在查询中添加 ORDER BY date_time 时出现 PHP 错误,我不明白为什么,因为它在网站的其他地方工作得很好。代码和错误如下:
// query responses
$sqlresponses = mysql_query("SELECT * FROM forum_replb ORDER BY date_time WHERE post_id='$disc_id'");
$responseList = "";
$numRows = mysql_num_rows($sqlresponses);
if ($numRows < 1) {
$responseList = "There are currently no responses to this discussion/post yet! Add one above.";
} else {
while($row = mysql_fetch_array($sqlresponses)){
$response_author_id = $row["author_id"];
$reply_body = $row["reply_body"];
$date_time = $row["date_time"];
$date_time = strftime("%b %d, %Y", strtotime($date_time));
$responseList .= '<div id="sub_response_module"><p>' . $reply_body . ' -
<a href="../profile.php?id=' . $response_author_id . '">' . $response_author_id . '</a>
| <i>' . $date_time . '</i></p></div>';
}
}
错误:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/lb/forum/post.php on line 49
澄清一下,第 49 行是 $numRows = mysql_num_rows($sqlresponses);。