title: Mysql user statistics
body: <p>Quick method description:</p>
  
  <p>I have two tables, lets name them table ONE and table TWO.
  Every table record has an id of its author (user). There are no limits for records per user.</p>
  
  <p>I would like to run a statistics page for each user. </p>
  
  <p>For example, when John logs in: </p>
  
  <p>John | 20 of A (list) | 150 of B (list)</p>
  
  <p><strong>Demo code</strong></p>
  
  <pre><code>$a = mysql_query("SELECT * FROM A WHERE userID='$userID'");
  $b = mysql_query("SELECT * FROM B WHERE userID='$userID'");
  
  $a_num=mysql_num_rows($a);
  $b_num=mysql_num_rows($b);
  
  $echo "$userID | $a_num of A &lt;a href='/a/$userID'&gt;(list)&lt;/a&gt; | $b_num of B &lt;a href='/b/$userID'&gt;(list)&lt;/a&gt; ";
  </code></pre>
  
  <p><strong>The question:</strong> </p>
  
  <p>So, is check for number of records (every time user visits his stats page) an optimal solution when number of table records come to few hundred or maybe thousand?
  Is there any better way to run statistics? Maybe a separate table which counts records for each user?</p>
  
  <p>Thanks :)</p>