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  
[snip]
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
realy 
is no other way of retrieving the count() directly, without passing by
the 
php function ?
[/snip]

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

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: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=1

Thread
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