I am doing a search page to find users. I have a qu query to find them, and in fact I can paginate using "LIMIT startRow, numberRows". But how can I calculate the total number of "registers" found before doing pagination? I would like to add to my search page the number of users found in the search.
I need something like: "Page 1 of 100". Actually, I have โPage 1โ, but I donโt know how to calculate the total number of results before paginate.
ยฟYou may need to complete an additional query with "SELECT COUNT (*)"? ยฟIs there any other way of counting before pagination to avoid another query?
I use two sql queries, one for one word and the other for verbose:
Basic sql query (to search by one word and several words):
"SELECT * FROM accounts AS A INNER JOIN profiles AS P ON A.account_id = P.account_id "
Single word condition:
"WHERE A.username LIKE ? OR P.name LIKE ? OR P.name LIKE ? OR P.surname LIKE ? OR P.surname LIKE ? LIMIT ?,?"
The state of a wordy word:
"WHERE CONCAT(P.name, ' ', P.surname) LIKE ? LIMIT ?,?"
Thank you very much.
source share