0

出于某种原因,这不起作用,但不知道为什么。我正在尝试获取有关数据库中有多少评论的评论 ID,但它显示为“0”。当我清楚地看到评论时。

现场访问:http ://www.krissales.me/#/media/articles

如果您单击文章链接,它将显示该页面上有多少评论,但不会显示我希望它显示的页面上。

我很确定它与以下内容有关:

$amount_get = mysql_query("SELECT * FROM comment WHERE id='" . mysql_real_escape_string($_GET['id']) . "'"); $comments = mysql_num_rows($amount_get);

文章.php:

<?php

        $amount_get = mysql_query("SELECT * FROM comment WHERE id='" . mysql_real_escape_string($_GET['id']) . "'"); 
        $comments = mysql_num_rows($amount_get);            

        $grab = mysql_query("SELECT * FROM articles WHERE id='" . mysql_real_escape_string($_GET['id']) . "' LIMIT 1");    
        $grab = mysql_query("SELECT id, news_title, news_content, news_author, news_day, news_month, news_year, news_date FROM articles ORDER BY id DESC limit 3"); 
        $news_day =$row['news_day'];
        $news_month =$row['news_month'];
        $news_year =$row['news_year'];


        if (mysql_num_rows($grab)==0) {
        echo "<div class='alert alert-note-x'>Sorry, it looks like their are no articles posted!</div>";
    }
        while($row = mysql_fetch_array($grab)){

    ?>

    <div class="post-container">
        <div class="post">
        <div class="left">
        <div class="date"><span class="day"><?php echo $row['news_day'] ?></span> <span class="month"><?php echo $row['news_month'] ?></span> <span class="year"><?php echo $row['news_year'] ?></span></div></div>
        <div class="postcontent"><h5 class="posttitle"><a href="#/media/<?php echo $row['id'] ?>.<?php echo stripslashes(str_replace(" ", "-", $row['news_title'])); ?>"><?php echo stripslashes($row['news_title']); ?></a></h5>                       
            <p>The content for this article will be posted here shortly, i need to edit some PHP that limits the chars for this section</p>
            <p>Comments (<?php echo $comments ?>)</p>
            </div>
    </div>​
    </div>  

  <?php } ?>
4

1 回答 1

2

你应该看看这一行的 WHERE 条件:

$amount_get = mysql_query("SELECT * FROM comment WHERE id='" . mysql_real_escape_string($_GET['id']) . "'"); 

我想id应该将其更改为article_id- 指向文章的 foreign_key。

于 2012-12-18T21:55:34.313 回答