List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 27 2000 12:05pm
Subject:Re: Getting Results: mysql_num_rows() and LIMIT
View as plain text  
At 8:59 PM -0700 08-26-2000, Matt Friedman wrote:
>PHP/MySQL question:
>When you use LIMIT in your sql statement, mysql_num_rows returns the number
>of rows returned after the limit statement in your sql.
>So, if your sql statement was something like:
>SELECT * FROM ... LIMIT 0,10 - mysql_num_rows() would return 10. (assuming
>there were at least 10 results) even thought there could be many more than
>10 results from the select.
>So how do you get the total number of results returned overall, as if your
>sql statement omitted the LIMIT part?
>That way you could limit the number of results displayed, but you would also
>know the total number of rows returned by your SELECT. Do you really have to
>run the sql statement twice?

Yes, because those are two different queries.

However: For the query that returns the total number of rows, you might
want to rewrite it to be SELECT COUNT(*) FROM ... with the rest of the
statement the same except for the LIMIT clause.  Then the client and serer
will not actually transfer the rows, just the count.  Read the first row
of the result set to get the count, don't use mysql_num_rows().

Paul DuBois, paul@stripped
Getting Results: mysql_num_rows() and LIMITMatt Friedman27 Aug
  • Re: Getting Results: mysql_num_rows() and LIMITPaul DuBois27 Aug