Wednesday 15 July 2015

php - COUNT of sql SELECT query with LIMIT in mySQL -


In php-mysql, how does the count of rows returning within a SELECT query count?
Select something like this query:

  $ q = "Choose from users LIMIT 20,60"   

But if the total number was just for example 55, the result is 20 to 55 users with 20 to 40 total users!
How can I get number 35 without asking DB twice?
I am doing this now:

  $ q = "Select COUNT (*) users limit of 20, 60"; $ Result = mysqli_query ($ db_connection, $ 1); $ Count = mysqli_fetch_row ($ result); $ Count = $ count [0];   

But here I am interrogating DB twice and I think it is not very good.
I know that I can have the total number of rows without regard to LIMIT , using SQL_CALC_FOUND_ROWS and FOUND_ROWS () , But this is not my case, because I want to consider the LIMIT Thanks!

you want

  $ count = $ result- & gt; ; NUM_ROWS;    

No comments:

Post a Comment