mysql - Recursion to display nested comments with PHP -


how can make below code same thing without unncessary repetition? assuming want display 10 replies top-level comment (and allow them continue on page)

on forum, mentioned can build them single database query or sort of recursive function. came (limited programming knowledge) said inefficient:

<?php  // query top-level comments, put each row in array  foreach ($comments $comment) {     // set variables (such submitter, date, comment text) ?>      html using variables, without last </div> tag      <?php      // query level-1 replies, put each in array      foreach ($replies1 $reply1) {          // set variables (such submitter, date, comment text)     ?>          html using variables without last </div> tag      <?php        // continue more foreach loops, last having </div> tag       ?>      <?php } $replies1 = array(); // reset ?>      </div> (to end container top-level in)  <?php } ?> 


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -