title: Which MySQL query is effective to get the total number of records
body: <p>To get the total number of records, I usually use this query:</p>
  
  <pre><code>$total= mysql_num_rows(mysql_query("SELECT id FROM t_statistic WHERE pageid = $pid"));
  </code></pre>
  
  <p>but I got one the other query like below:</p>
  
  <pre><code>$data = mysql_fetch_object(mysql_query("SELECT COUNT(id) AS num_rows FROM t_statistic WHERE pageid = $pid"));
  $total = $data-&gt;num_rows;
  </code></pre>
  
  <p>Between the two queries above. Which is more quickly and effectively (when the total number of records in the millions)?</p>