[snip]
> I agree that COUNT is an optimized return, but for a situation where
you
> are
> retrieving data from the query for whatever use it is more efficient
to
> use
> mysql_num_rows() to return the count of this particular query than it
> would
> be to issue a second query, no?

Yes, it all depends on what you are doing with the results. If you are
selecting everything, and using everything in your page, then, yeah, use
mysql_num_rows. A second query of the same thing just for COUNT(*) would
be inefficient. 

> I guess we could get into some semantical discussion at this point
about
> efficiency. I am an old school coder, and as such I have been taught
to
> conserve CPU cycles and round trips to other servers. As technology
grows
> some of these things could go by the wayside because processing power
has
> increased multi-fold since I began my foray many years ago. I always
seek
> to
> send the fewest queries to the database server where possible...
efficient
> query design, use of other functions available in the programming
language
> to provide additional data, or any number of other tricks, tips, and
magic
> tricks have helped to keep things clean.
> 
> So, is mysql_num_rows() less efficient than a second query asking
SELECT
> COUNT(*)? Is there any way to time the two where doing a query like
the
> above example?

The two query method is efficient when you have large tables and you are
only going to use a subset of the results. Like in showing X records out
of Y. 

I could do a little benchmarking script to see what kind of time
differences we are talking about. Maybe it's so minor that it doesn't
matter...

I think we're arguing with each other even though we agree on
everything. :)

---John Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to