List:General Discussion« Previous MessageNext Message »
From:Jay Blanchard Date:March 28 2006 10:10pm
Subject:RE: Re: Li'l problem with count()
View as plain text  
I think that the fastest method and the cheapest one is using "select 
count(*) from table" and using mysql_num_rows(), isn't it ? but there
is no other way of retrieving the count() directly, without passing by
php function ?

Actually, SELECT COUNT only returns one row, the count of the table. Do

Select count(*) AS foo from table

$bar = mysql_fetch_array($result);
Echo $bar['foo'];

Faster and more efficient since MySQL maintains this information in an
indexed sort of way. If you do

Select * from table

$result = mysql_query

Echo mysql_num_rows($result);

That counts the rows actually returned in the result set.

MySQL General Mailing List
For list archives:
To unsubscribe:

Li'l problem with count()Sandy28 Mar
  • Re: Li'l problem with count()Peter Brawley28 Mar
RE: Li'l problem with count()Jay Blanchard28 Mar
  • Re: Li'l problem with count()Sandy28 Mar
  • Re: Li'l problem with count()Sandy28 Mar
RE: Re: Li'l problem with count()Jay Blanchard29 Mar