Re: counting number of records in a MySQL table; how do I get

From: Date: Thu, 03 Oct 2002 14:22:44 +0000
Subject: Re: counting number of records in a MySQL table; how do I get
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-118747@lists.php.net to get a copy of this message
> $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? ---John Holmes...

« previous php.general (#118747) next »