使用AJAX显示更多评论 - 如何停止显示已加载的评论?

时间:2017-06-07 12:41:45

标签: javascript php jquery ajax

这是ideas.php:

<?php
$postshow = "SELECT * FROM ideas_1 ORDER BY consents DESC LIMIT 10";
$done = mysqli_query($conn, $postshow);
//$show = mysqli_fetch_assoc($done);

while ($show = mysqli_fetch_assoc($done)) {
    $postid = $show['postid'];
    $userid = $show['userid'];
    $consents = $show['consents'];?>
   <div class = 'comments'>
    <?php echo$show['post'];?><br>
   <span class = 'counter'><?php echo$show['consents'];?></span> <span>Consents</span>

     <?php $asd = "SELECT * FROM consents WHERE dept = 'ideas' and task = '1' and postid = '$postid' and voterid = '$id'";
      $doit = mysqli_query($conn, $asd);
      $exist = mysqli_num_rows($doit);
      if ($exist == 0){ ?>
    <button class = 'consents' data-postid = '<?php echo$postid;?>' data-posterid ='<?php echo$userid;?>'
    data-voterid = '<?php echo$id;?>' data-consents = '<?php echo$consents;?>' >Consent This</button>
     <?php } ?>

   </div>


<?php }
?>
<?php
     $more = "SELECT * FROM ideas_1";
     $more1 = mysqli_query($conn, $more);
     if (mysqli_num_rows($more1)>10) {
     ?>
     <button id = 'showmore'>Show more</button>
     <?php }?>

点击“显示更多”按钮(<button id = 'showmore'>Show more</button>)后,我想要显示更多评论。它的click函数在JQuery中:

$("#showmore").click(function(){
    commentCount = commentCount + 1;
    $('.comments').load("load-ideas.php", {
        commentNewCount: commentCount
        });
    });

这是load-ideas.php:

<?php
session_start();
if (isset($_SESSION['id'])){
    $id = $_SESSION['id'];
} else {
    header("Location: index.php");
}
include('dbh.php');
$commentNewCount = $_POST['commentNewCount'];

$postshow = "SELECT * FROM ideas_1 ORDER BY consents DESC LIMIT $commentNewCount";
$done = mysqli_query($conn, $postshow);


while ($show = mysqli_fetch_assoc($done)) {
    $postid = $show['postid'];
    $userid = $show['userid'];
    $consents = $show['consents'];?>
   <div class = 'comments'>
    <?php echo$show['post'];?><br>
   <span class = 'counter'><?php echo$show['consents'];?></span> <span>Consents</span>

     <?php $asd = "SELECT * FROM consents WHERE dept = 'ideas' and task = '1' and postid = '$postid' and voterid = '$id'";
      $doit = mysqli_query($conn, $asd);
      $exist = mysqli_num_rows($doit);
      if ($exist == 0){ ?>
    <button class = 'consents' data-postid = '<?php echo$postid;?>' data-posterid ='<?php echo$userid;?>'
    data-voterid = '<?php echo$id;?>' data-consents = '<?php echo$consents;?>' >Consent This</button>
     <?php } ?>

   </div>


<?php }
?>

所以这段代码基本上显示了已加载的评论+更多评论。我只想展示其他评论。那我怎么能这样做呢?

0 个答案:

没有答案