title: PHP Template Buffering in a Loop
body: <p>I'm basically running a loop on a query and using PHP's buffering to insert a template file in the loop.  The problem is if I have more than one result in my query I end up with two or more identical results (loops the same data rather than the next in the mysql result row).</p>
  
  <p>the function...</p>
  
  <pre><code>function get_blocks(){
      $query = "SELECT * FROM `my_table`";
      $results = mysql_query($query);
  
      while($data = mysql_fetch_assoc($results){
          extract($data, EXTR_SKIP);
          ob_start();
          include(dirname(__FILE__) . '/templates/infoBlock.php');
          $returnString .= ob_get_clean();
      }
      echo $returnString;
  }
  </code></pre>
  
  <p>The template looks like:</p>
  
  <pre><code>&lt;div&gt;
      Hi my name is &lt;?php echo $name; ?&gt;
      &lt;br&gt;
      and my age is &lt;?php echo $age; ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So, if I have two records:</p>
  
  <pre><code>record 1
  name: Joe
  age: 42
  
  record 2
  name: Sam
  age: 35
  </code></pre>
  
  <p>I end up with</p>
  
  <pre><code>Hi my name is Joe
  and my age is 42
  
  
  Hi my name is Joe
  and my age is 42
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>Hi my name is Joe
  and my age is 42
  
  
  Hi my name is Sam
  and my age is 35
  </code></pre>
  
  <p>I've already tried </p>
  
  <pre><code>echo ob_get_clean(); 
  </code></pre>
  
  <p>and taking $returnString out of the function to no avail...</p>
  
  <p>thoughts?</p>