title: PHP while loop echoing duplicates
body: <p>I need some help with some methodology</p>
  
  <p>I have a SQL statement that fetches results from a <code>questions</code> 'header table'.</p>
  
  <p><code>while()</code> the data is being fetched I'm running another SQL statement that pulls <code>comments</code> from a 'sub table' according to the <code>id</code> fetched from the <code>questions</code> table.</p>
  
  <p>When I echo all together, <code>question</code> number 1's <code>comments</code> show fine, all the comments related to the <code>question</code> are showing fine.</p>
  
  <p>The issue is when <code>question</code> number 2's <code>comments</code> are echoed, comments from <code>question</code> number 1 show up (duplicated).</p>
  
  <p>I just can't figure out where I'm going wrong.</p>
  
  <p>Here's a simplified version of what my code looks like just to show the methodology:</p>
  
  <pre><code>$comment_list = ""; // to display comments
  $GET_QUESTIONS = $DBH-&gt;prepare("SELECT ...");
  // parameters are bound here using $GET_STATEMENTS-&gt;bindParam();
  
  while($row = $GET_QUESTIONS-&gt;fetch(PDO::FETCH_ASSOC)){
  
      $question_id = $row['id'];
      $question_string = $row['string'];
  
      // NOW I PULL THE COMMENTS
      $GET_COMMENTS = $DBH-&gt;prepare("SELECT ...");
      // parameters are bound here using $GET_COMMENTS-&gt;bindParam();
  
      while($row = $GET_COMMENTS-&gt;fetch(PDO::FETCH_ASSOC)){
  
          $comment_id = $row['id'];
          $comment_string = $row['string'];
  
          $comment_list .= "
              &lt;p&gt;" .$comment_string. "&lt;/p&gt;
          ";
  
      }
  
      echo "
          &lt;h1&gt;" .$question_string. "&lt;/h1&gt;
          " .$comment_list. "
  
      ";
  
  }
  </code></pre>
  
  <p>Why are the duplicates happening when echoing the second <code>question</code>?</p>