title: SELECT COUNT() vs mysql_num_rows();
body: <p>I have a large table (60+) millions of records.</p>
  
  <p>I'm using PHP script to navigate through this table.</p>
  
  <p>PHP script (with pagination) loads very fast because:</p>
  
  <p>The table engine is InnoDB thus <code>SELECT COUNT()</code> is very slow and <code>mysql_num_rows()</code> is not an option, so i keep the total row count (the number that i use to generate pagination) in a separate table (i update this record <code>total_rows=total_rows-1</code> and <code>total_rows=total_rows1+1</code> during <code>DELETE</code> and <code>INSERT</code>).</p>
  
  <p>But the question is what to do with the pagination for search results?</p>
  
  <p>Right now I'm doing this with 2 steps:</p>
  
  <p>1.</p>
  
  <pre><code>$condition = " fname='rinchik' ";
  $result = "SELECT * FROM my_large_table WHERE" . $condition;
  </code></pre>
  
  <p>Here i got all search results from DataBase.</p>
  
  <p>2.
  Now i need to count these results to create pagination.
  I'm doing this:</p>
  
  <pre><code>$condition; &lt;- we already have this from the step 1
  $result_count = "SELECT COUNT(id) FROM my_large_table WHERE" . $condition;
  </code></pre>
  
  <p>And it's kinda slow.</p>
  
  <p>Would it be better if i will do it this way (with just one step)?:</p>
  
  <pre><code>$condition = " fname='rinchik' ";
  $result = "SELECT * FROM my_large_table WHERE" . $condition;
  $result_count = mysql_num_rows($result);
  </code></pre>