我试图让我的文章获取它有多少评论,并显示数字。这里的代码:SQL语法显示日期
<?php
$amount_get = mysql_query("SELECT * FROM comment WHERE id='" . mysql_real_escape_string($_GET['articleid']) . "'");
$comments = mysql_num_rows($amount_get);
$grab = mysql_query("SELECT id, news_title, news_content, news_date, news_author FROM articles ORDER BY id DESC LIMIT 5");
while($row = mysql_fetch_array($grab)){
?>
<div class="pane">
<li>
<h2><?php echo $row['news_title'] ?></h2>
<div class="meta">
<span class="color"> • </span>
<?php echo $row['news_date'] ?>
<span class="color"> • </span>
</div>
Comments: <?php echo $comments ?>
但由于某种原因,它保持在“0”。这是它的样子:
和我的列是id,articleid,名称,注释,日期& ip。
究竟是什么问题? – Jeremy1026 2013-03-04 16:02:06
@ Jeremy1026 - 问题基本上是“为什么'mysql_num_rows()'返回零?” – 2013-03-04 16:02:53
你是否确定articles.id匹配comments.id?这意味着每篇文章最多只能有一条评论。你需要查看表格之间的关系。 – 2013-03-04 16:07:19