title: Is it possible to avoid query in loop?
body: <p>I have such code:</p>
  
  <pre><code>$q = "SELECT date FROM t1 GROUP BY date";
  $pdo-&gt;query($q);
  $results = $pdo-&gt;results();
  
  foreach($results as $result) {
      echo "&lt;h1&gt;$result['date']&lt;/h1&gt;";
      echo "&lt;table&gt;";
  
      $q = "SELECT * FROM t1 WHERE date=:date";
      $pdo-&gt;query($q);
      $pdo-&gt;bind("date", $result['date']);
      $subresults = $pdo-&gt;resultset();
  
      foreach($subresults as $sub) {
          echo "&lt;tr&gt;&lt;td&gt;$sub['smth']&lt;/td&gt;&lt;/tr&gt;";
      }
  
      echo "&lt;/table&gt;";
  }
  </code></pre>
  
  <p>It reads dates from database and prints separate tables with data. It is possible to achieve this without having query in a loop?</p>