Re: mysql_num_rows
| From: | liljim | Date: | Wed, 18 Dec 2002 10:10:34 +0000 |
| Subject: | Re: mysql_num_rows | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-128673@lists.php.net to get a copy of this message | ||
Hi John,
"John Taylor-Johnston" wrote in message:
> I use $mycounter, not saying it is pretty. But if you have a whole bunch
of stuff deleted, your last id might be worth a lot more than the actual
number of rows.
>
> $myconnection = mysql_connect($server,$user,$pass);
> mysql_select_db($db,$myconnection);
>
> $news = mysql_query('select * from '.$table.' where '.$where.' order
> by id
asc');
> $mycounter = 0;
> while ($mydata = mysql_fetch_object($news))
> {
> $mycounter++;
> }
Have you ever considered just doing a count()?
$count = @mysql_query("select count(*) from [table(s)] where [criteria
[group by something]]");
$total = mysql_result($count, 0);
That will return the number of rows in your table(s). It's also much quicker
and less resource intensive, particularly with large datasets. :)
James