[snip]
> $result = mysql_query("SELECT * FROM tbl");
> $number_of_rows = mysql_num_rows($result);
>
> You don't have to do the count in the SQL, as John said earlier a SELECT
> COUNT(*) FROM tbl will always return one row, even if the value of the row
> is 0. Of course you could always test for that.
>
> CountingRows Solution #317 :^]

That's a really ineffecient solution, though. COUNT() of optimized to return
a quick result. Why would you select everything and use up all of those
resources to just get a count of the rows?
[/snip]

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.

HTH!

Jay



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

Reply via email to