MySQL - How to count rows before pagination?
<p>I am making a search page to find users. I have que query to find them and actually I can do the pagination with "LIMIT startRow, numberRows". But how could I count the total number of "registers" found before doing the pagination? I would like to add at my search page, the number of the users found in a search.</p>

<p>I need something like: "Page 1 of 100". I actually I have "Page 1" but I don't know how to count the total of results before paginate.</p>

<p>¿Maybe could be necesary execute an extra query with "SELECT COUNT(*)"? ¿Is there another way to count before pagination to avoid another query?</p>

<p>I use two sql queries, one for single word, and another for multiword:</p>

<p>Base sql query (for single word and multi word search):</p>

<pre><code>"SELECT * FROM accounts AS A INNER JOIN profiles AS P ON A.account_id = P.account_id "
</code></pre>

<p>Single word condition:</p>

<pre><code>"WHERE A.username LIKE ? OR P.name LIKE ? OR P.name LIKE ? OR P.surname LIKE ? OR P.surname LIKE ? LIMIT ?,?"
</code></pre>

<p>Multi word condition:</p>

<pre><code>"WHERE CONCAT(P.name, ' ', P.surname) LIKE ? LIMIT ?,?"
</code></pre>

<p>Thanks a lot.</p>