title: Statistic gathering from database
body: <p>I have an app that's competition based, and includes (lets say) 10 types of biscuit (cookies) and 6 types of drinks. I'm using MODx Revolution 2.2 as the CMS.</p>
  
  <p>Entrants basically specify which kind of drink they'd like and enter a barcode (relating to the type of biscuit).</p>
  
  <p>I want to present this inside the CMS as a statistic, but I imagine it's quite resource intensive to query the database for each <code>COUNT()</code>.</p>
  
  <pre><code>$biscuit1 = $modx-&gt;query("SELECT COUNT(*) FROM my_table WHERE barcode = '1234'");
  $biscuit1 = $modx-&gt;fetch(PDO::FETCH_ASSOC);
  $biscuit1 = $biscuit1[0];
  </code></pre>
  
  <p>So my questions are:</p>
  
  <ul>
  <li>Is doing 16 database queries (possibly more) bad practice?</li>
  <li>If there is a better way of gathering statistics on datasets, what is it?</li>
  </ul>
  
  <p>Note: I had a thought of creating another statistics table, where I run these queries in a cron job on the hour. Would this help?</p>