评论仅在最后一篇文章后出现

时间:2011-07-23 17:46:20

标签: php mysqli

我为用户发帖评论页面,其他人可以评论他们的帖子运行非常好但是有一个问题我认为这很容易但我无法得到它,当用户评论帖子'一'它看起来正常,但是当有3或5等时,评论一个看起来并不像它不存在那么最后我可以非常清楚地表明最后的帖子评论出现但是如果有任何其他评论在顶部它。它没有出现

这是我的代码

<?php
    >               
    >       $getBlogs = "select * from blogs where active = 1";
    >       $blogResults = $db -> query ($getBlogs) or die ($db->error);        if
    > ($blogResults) {
    >                       while ($blog = $blogResults -> fetch_object()) {
    >               
    >               ?>
    >               
    >                 
    >                 
    >                 <table width="600" border="0" cellpadding="0"
    > cellspacing="0">
    >                   <tr class="bons">
    >                     <td width="62" align="right" valign="middle"
    > class="blogIBg"><img src="images/blog.png" width="37" height="30"
    > /></td>
    >                     <td width="243" height="28" class="blogSBg"><?php
    > echo $blog->Btitle; ?></td>
    >                     <td width="78" height="28" class="blogSBg"><span
    > class="by11">Posted by :</span></td>
    >                     <td width="117" height="28" class="blogSBg"><span
    > class="blogby12Bg"><span class="red"><b><?php echo $blog->ByName;
    > ?></b></span></span></td>
    >                     <td width="100" class="blogSBg"><span
    > class="by11"><?php echo $blog->dateAdded ?></span></td>
    >                   </tr>
    >                   <tr>
    >                     <td>&nbsp;</td>
    >                     <td colspan="4" class="blogBBg"><?php echo
    > $blog->Bdescription; ?></td>
    >                   </tr>
    >                   <tr>
    >                     <td>&nbsp;</td>
    >                     <td colspan="4" align="right" bgcolor="#D5F1FF"
    > class="blogby11Bg"><a class='example7'
    > href="includes/postComments.php?id=<?php $gotIT=$blog->id; echo
    > $gotIT; ?>">Comment</a></td>
    >                   </tr>
    >                 </table>
    >                 <br />               
    >                    <?php
    >               
    >               }           }
    >                       $comments = "select * from blogscomments where blogestID =
    > $gotIT";          $resultComments = $db -> query ($comments) or die
    > ($db->error);
    >                       if ($resultComments) {
    >               
    >               
    >                   while ($dig = $resultComments -> fetch_object()) {
    >                        ?>
    >                       
    >                           <table width="500" border="0">
    >                               <tr>
    >                                 <td width="32">&nbsp;</td>
    >                                 <td width="197"><?php echo
    > $dig->comments; ?></td>
    >                               </tr>
    >                             </table>
    >                             
    >                             
    >                       <?php
    >                       
    >                       }
    >               
    >               } ?>
    > 
    > </div>

我输入了整个代码,以提供完整的想法,

并且代码负责显示的评论是这个。

$comments = "select * from blogscomments where blogestID =
 $gotIT";             $resultComments = $db -> query ($comments) or die
 ($db->error);
                      if ($resultComments) {


                   while ($dig = $resultComments -> fetch_object()) {
                        ?>

                          <table width="500" border="0">
                              <tr>
                                <td width="32">&nbsp;</td>
                               <td width="197"><?php echo
 $dig->comments; ?></td>
                               </tr>
                             </table>


                       <?php

                       }

               } ?>

1 个答案:

答案 0 :(得分:0)

感谢大家,我刚刚得到它,这很容易就像我一边做了一个名为handlingComments.php的单独的php文件,我把这个代码按原样放置

<?php

$comments = "select * from blogscomments where blogestID = $gotIT";
            $resultComments = $db -> query ($comments) or die ($db->error);

            if ($resultComments) {


                    while ($dig = $resultComments -> fetch_object()) {

     ?>               
                    <table width="500" border="0">
                              <tr>
                                <td width="32">&nbsp;</td>
                                <td width="197"><?php echo $dig->comments; ?></td>
                              </tr>
                            </table>


                        <?php

                        }

                }
?> 

然后我加入了主要的博客页面,它现在运行得非常好。

再次感谢大家,