Slice () Jquery + loop php ("load more comments")

0

I have the following problem, I have created a method to load more content or the famous Load More . I used slice() in jquery with loadcomentid to make the application, however when I put a query in the php bank inside the slice some divs disappear. The query is extremely necessary so that I can get the answers from each comment and put it directly below.

Code where the query is within the div loadcomentid inside contains the replys div that are the response of each comment.

       <div class="yourcoment loadcomentid">
     <div class="imagem" style="margin-top: 5px;width: 8%;">
      <a href="perfil?id=<?php echo $assocuserpost['id']; ?>"><img class="imagem" title="<?php echo $assocuserpost['usuario'] ?>" width="50" height="50" src="imgperfil/<?php echo $assocuserpost['foto'] ?>.jpg" /></a>
     </div>
     <div class="formcomentado">
      <div class="inputcoment">
        <p><a href="perfil?id=<?php echo $assocuserpost['id']; ?>" class="nomecss" style="font-size: 14px;"><?php echo $assocuserpost['usuario'] ?></a> <?php echo $dados2['comentario'] ?></p>
      </div>
      <p style="float: left; font-size: 12px"><span class="responder reply-<?php echo $dados2['id']; ?>" id="usuario-<?php echo $assocuserpost['usuario'] ?>" onclick="responder(<?php echo $dados2['id']; ?>,<?php echo $dados['id'] ?>)">Responder</span> - <?php echo date('d/m/Y H:i', strtotime($dados2['datetime'])); ?></p>
      <?php 
      if ($usuariocomentario == $usuario){ ?>

        <p class="excluir excluirid-<?php echo $dados['id'] ?>" id="excluir-<?php echo $dados2['id']; ?>" onclick="excluircoment(<?php echo $dados2['id']; ?>)" >Excluir</p>

      <?php } ?>
     </div>
  <div class="newreply" id="novaresposta-<?php echo $dados2['id'] ?>"></div>
<?php
    $contar = mysqli_num_rows(mysqli_query($conn,"SELECT * FROM comentarios WHERE reply = '$idcomentario'"));
    if($contar != '0') {

      $reply = mysqli_query($conn,"SELECT * FROM comentarios WHERE reply = '$idcomentario' ORDER BY id DESC");
      while($rep=mysqli_fetch_array($reply)) {

      $usuario2 = mysqli_query($conn,"SELECT * FROM usuario WHERE usuario = '".$rep['usuario']."'");
      $user2 = mysqli_fetch_array($usuario2);
  ?>
  <div class="replys">
       <div class="yourcoment">
         <div class="imagem" style="margin-top: 5px;width: 8%;">
          <a href="perfil?id=<?php echo $user2['id']; ?>"><img class="imagem" title="<?php echo $user2['usuario'] ?>" width="50" height="50" src="imgperfil/<?php echo $user2['foto'] ?>.jpg" /></a>
         </div>
         <div class="formcomentado">
          <div class="inputcoment">
            <p><a href="perfil?id=<?php echo $user2['id']; ?>" class="nomecss" style="font-size: 14px;"><?php echo $user2['usuario'] ?></a> <?php echo $rep['comentario'] ?></p>
          </div>
          <p style="float: left; font-size: 12px"><span class="responder reply-<?php echo $dados2['id']; ?>" id="usuario-<?php echo $rep['usuario'] ?>" onclick="responder(<?php echo $dados2['id']; ?>,<?php echo $dados['id'] ?>)">Responder</span> - <?php echo date('d/m/Y H:i', strtotime($rep['datetime'])); ?></p>
          <?php 
          if ($usuariocomentario == $usuario){ ?>

            <p class="excluir excluirid-<?php echo $dados['id'] ?>" id="excluir-<?php echo $rep['id']; ?>" onclick="excluircoment(<?php echo $rep['id']; ?>)" >Excluir</p>

          <?php } ?>
         </div>
      </div>
     </div>
   </div>
  <?php } } } ?>

image1 = Code 1.

image2=Code2(belowimage2).

Codewithoutthequeryinthebank:Note:thequeryisimportantsothatIcanshowtheanswerswithineachcomment.

<divclass="yourcoment loadcomentid">
     <div class="imagem" style="margin-top: 5px;width: 8%;">
      <a href="perfil?id=<?php echo $assocuserpost['id']; ?>"><img class="imagem" title="<?php echo $assocuserpost['usuario'] ?>" width="50" height="50" src="imgperfil/<?php echo $assocuserpost['foto'] ?>.jpg" /></a>
     </div>
     <div class="formcomentado">
      <div class="inputcoment">
        <p><a href="perfil?id=<?php echo $assocuserpost['id']; ?>" class="nomecss" style="font-size: 14px;"><?php echo $assocuserpost['usuario'] ?></a> <?php echo $dados2['comentario'] ?></p>
      </div>
      <p style="float: left; font-size: 12px"><span class="responder reply-<?php echo $dados2['id']; ?>" id="usuario-<?php echo $assocuserpost['usuario'] ?>" onclick="responder(<?php echo $dados2['id']; ?>,<?php echo $dados['id'] ?>)">Responder</span> - <?php echo date('d/m/Y H:i', strtotime($dados2['datetime'])); ?></p>
      <?php 
      if ($usuariocomentario == $usuario){ ?>

        <p class="excluir excluirid-<?php echo $dados['id'] ?>" id="excluir-<?php echo $dados2['id']; ?>" onclick="excluircoment(<?php echo $dados2['id']; ?>)" >Excluir</p>

      <?php } ?>
     </div>
     </div>

Slice jquery code:

$(function(){
$(".comentcontent").each(function( index ) {
$(this).find(".loadcomentid").slice(0, 5).show();
if ($(this).find(".loadcomentid:hidden").length != 0) {
    $(this).find(".loadcoment").show();
  }

  $(".loadcoment").on('click', function (e) {
    e.preventDefault();
    $(this).parent().find(".loadcomentid:hidden").slice(0, 6).show();
    if ($(this).parent().find(".loadcomentid:hidden").length == 0) {
      $(this).hide();
    }
  });
});
});
    
asked by anonymous 02.01.2019 / 17:49

0 answers