title: Load more data from database button PHP
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>   &lt;section class="comments-section" id="comments"&gt;
    
        &lt;h2 class="h2 center"&gt;Partagez vos temoignages &lt;/h2&gt;
        &lt;p class="paragraph center"&gt;Laissez la haine et le mépris à l'extérieur ! Ici on écrit que des choses positives.&lt;/p&gt;
      &lt;div class="container"&gt;
        &lt;form method="POST" id="comment_form"&gt;
         &lt;div class="form-group"&gt;
          &lt;input type="text" name="comment_name" id="comment_name" class="form-control" placeholder="Nom ou pseudo" /&gt;
         &lt;/div&gt;
         &lt;div class="form-group"&gt;
          &lt;textarea style="resize: none;" name="comment_content" id="comment_content" class="form-control" placeholder="Redigez votre commentaire" maxlength="700" rows="10"&gt;&lt;/textarea&gt;
         &lt;/div&gt;
         &lt;div class="form-group"&gt;
          &lt;input type="hidden" name="comment_id" id="comment_id" value="0" /&gt;
          &lt;input type="submit" name="submit" id="submit" class="btn btn-success" value="Publier" /&gt;
         &lt;/div&gt;
        &lt;/form&gt;
        &lt;span id="comment_message"&gt;&lt;/span&gt;
        &lt;br /&gt;
      
  
        &lt;div class="all-comments" id="all"&gt;
    
              &lt;div class="content" id="display_comment"&gt;&lt;/div&gt;
              
          
        &lt;/div&gt;
  
  
  &lt;/section&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I have comment system on my website and I would like to add Load More button to hide comments and show only the first three and to load the rest of comments when clicked on button. These comments are from my DB. I have tried a lot of exemples but I'm still stucking...</p>
  <p>Have you any solution please? Thanks</p>
  <pre><code>&lt;?php
  
  //fetch_comment.php
  
  $connect = new PDO('mysql:host=localhost;dbname=testing', 'root', '');
  
  // select from DB
  
  $query = &quot;
  SELECT * FROM comments 
  WHERE parent_comment_id = '0' 
  ORDER BY comment_id DESC LIMIT 3
  &quot;;
  
  $statement = $connect-&gt;prepare($query);
  
  $statement-&gt;execute();
  
  $result = $statement-&gt;fetchAll();
  $output = '';
  foreach($result as $row)
  {
   $output .= '
   &lt;div class=&quot;panel panel-default&quot;&gt;
    &lt;div class=&quot;panel-heading&quot;&gt;Par &lt;b&gt;'.$row[&quot;comment_sender_name&quot;].'&lt;/b&gt; le &lt;i&gt;'.$row[&quot;date&quot;].'&lt;/i&gt;&lt;/div&gt;
    &lt;div class=&quot;panel-body&quot;&gt;'.$row[&quot;comment&quot;].'&lt;/div&gt;
    &lt;div class=&quot;panel-footer&quot; align=&quot;right&quot;&gt;&lt;button type=&quot;button&quot; style=&quot;font-size:1rem;&quot;class=&quot;btn btn-default reply&quot; id=&quot;'.$row[&quot;comment_id&quot;].'&quot;&gt;Répondre&lt;/button&gt;&lt;/div&gt;
   &lt;/div&gt;
   
   ';
  
   
   $output .= get_reply_comment($connect, $row[&quot;comment_id&quot;]);
  }
  
  echo $output;
  
  function get_reply_comment($connect, $parent_id = 0, $marginleft = 0)
  {
   $query = &quot;
   SELECT * FROM comments WHERE parent_comment_id = '&quot;.$parent_id.&quot;'
   &quot;;
   $output = '';
   $statement = $connect-&gt;prepare($query);
   $statement-&gt;execute();
   $result = $statement-&gt;fetchAll();
   $count = $statement-&gt;rowCount();
   if($parent_id == 0)
   {
    $marginleft = 0;
   }
   else
   {
    $marginleft = $marginleft + 48;
   }
   if($count &gt; 0)
   {
    foreach($result as $row)
    {
     $output .= '
     &lt;div class=&quot;panel panel-default&quot; style=&quot;margin-left:'.$marginleft.'px&quot;&gt;
      &lt;div class=&quot;panel-heading&quot;&gt;By &lt;b&gt;'.$row[&quot;comment_sender_name&quot;].'&lt;/b&gt; le &lt;i&gt;'.$row[&quot;date&quot;].'&lt;/i&gt;&lt;/div&gt;
      &lt;div class=&quot;panel-body&quot;&gt;'.$row[&quot;comment&quot;].'&lt;/div&gt;
      &lt;div class=&quot;panel-footer&quot; align=&quot;right&quot;&gt;&lt;button type=&quot;button&quot; style=&quot;font-size:1rem;&quot; class=&quot;btn btn-default reply&quot; id=&quot;'.$row[&quot;comment_id&quot;].'&quot;&gt;Répondre&lt;/button&gt;&lt;/div&gt;
     &lt;/div&gt;
     ';
     $output .= get_reply_comment($connect, $row[&quot;comment_id&quot;], $marginleft);
    }
   }
   return $output;
  }
  
  ?&gt;
  </code></pre>