Re: best way to get COUNT from result set

From: Date: Wed, 20 Dec 2000 02:09:12 +0000
Subject: Re: best way to get COUNT from result set
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31123@lists.php.net to get a copy of this message
use field aliases. "SELECT COUNT(id) AS cnt FROM table" $row["cnt"] now has the value from MySQL's COUNT() alternately, you could use "SELECT * FROM table" then mysql_num_rows() on the result. Christian Dechery wrote: > > there's no way to get a single result from a query (since several functions > like MAX(), AVG(), COUNT(), ...) return single values... > > I could go like... > > $q = "select count(id) from table"; > $rslt = mysql_query($q); > $count = mysql_fetch_row($rslt); > > and then $count[0] would have what I want... > but this is kinda "syntax ugly"... I only want ONE value... I don't want an > ARRAY... > of course $count = $count[0] (I'm sure a lot of people would sugest that) > is possible, but is also "syntax ugly"... > > is there any way around this? > ____________________________ > . Christian Dechery (lemming) > . http://www.tanamesa.com.br > . Gaita-L Owner / Web Developer > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#31123) next »