title: While Loop Inside a While Loop
body: <p>I have a comment box wherein users can post comments. These comments will be displayed in a while loop.</p>
  
  <pre><code>&lt;?php
  
  while ($rowsx=mysql_fetch_array($resultss1)){
  
  echo "&lt;div id='comments'&gt;";
  echo "&lt;table class='table11'&gt;";
  echo "&lt;tr&gt;";
  echo "&lt;td class='sss'&gt;&lt;img src='img/user.jpg'&gt;";
  echo "&lt;p class='p999'&gt;"  .$rowsx['username'];  
  echo  "&lt;/p&gt; &lt;/br&gt;";
  echo "&lt;p class='p9date'&gt;" .$rowsx['date_posted']. "&lt;/p&gt; ";
  echo "&lt;/td&gt;";
  echo "&lt;td&gt;";
  echo "&lt;p class='p9'&gt;" .$rowsx['comment']. "&lt;/p&gt; &lt;/br&gt;&lt;/br&gt;&lt;/br&gt;";
  
  
  echo "&lt;/td&gt;";
  
  echo "&lt;/tr&gt;";
  echo "&lt;/table&gt;";
  
  echo "&lt;a href='reply1.php?r_comment=".$rowsx['comment']."&amp;prod_id=".$row['prod_id']."'    class='reply_button'&gt; REPLY &lt;/a&gt;  ";
  echo "&lt;/div&gt;";
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>Now other users can also reply to the comments of the user. I want to display their replies below each comments of other users but I can't seem to figure out how to do that.</p>
  
  <p>Should I use another while loop inside the first while loop?</p>
  
  <p>Sorry if I'm using mysql functions I know it's depreciated but its just a school project.</p>
  
  <p>Here is my query for displaying comments:</p>
  
  <pre><code>$display_comments1="Select username,prod_id,comment,DATE_FORMAT(date_posted, '%m/%d/%Y %H:%i:%s' ) AS date_posted from comment where prod_id='$prod_id' order by date_posted DESC";
  $resultss1=mysql_query($display_comments1);
  
  if($resultss1 === FALSE) {
  die(mysql_error()); // TODO: better error handling
  }
  </code></pre>