Re: counting number of records in a MySQL table; how do I get
| From: | 1LT John W. Holmes | Date: | Thu, 03 Oct 2002 15:15:18 +0000 |
| Subject: | Re: counting number of records in a MySQL table; how do I get | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-118758@lists.php.net to get a copy of this message | ||
> I was thinking along the lines that there needed to be a query that
returned
> some results that may also be displayed or used within the script. For
> instance, I use a paging script that queries for certain conditions and
> returns 40 records per page. I also display a line that says, "There are x
> records based on the criteria that you have selected.". x comes from
> mysql_num_rows. Now, if all I had to do was get the number of records I
> would use sql COUNT and test for the condition by seeing what number was
> returned by the COUNT.
I still think it's more effecient to use two queries in your case. One with
a COUNT(*) to get total records, and one with a LIMIT to just get the 40 you
want. With a smaller table, it may not matter, but with large tables, you
could be using up a lot of resources by selecting everything, but then only
using 40 rows of it.
You already have the connection open, so two efficient queries would still
be quick.
---John Holmes...