Re: COUNT(*) Output Question
| From: | John W. Holmes | Date: | Mon, 02 Aug 2004 20:26:19 +0000 |
| Subject: | Re: COUNT(*) Output Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-192494@lists.php.net to get a copy of this message | ||
From: "Tom Ray [Lists]" <lists@blazestudios.com>
> $count=mysql_query("SELECT sku, COUNT(*) FROM orders GROUP BY sku");
>
> But my question is how do I use PHP to output the COUNT(*) results? When
> I run the command when I'm logged into mySQL I get the following:
I assume you're fetching associative arrays from the result and $r['sku']
works, but you're not sure how to get the COUNT(*) value? Well,
$r['COUNT(*)'] would work, but you could also use an alias:
SELECT sku, COUNT(*) AS mycount FROM orders GROUP BY sku
and then use $r['mycount'] to retrieve the value (after using
mysql_fetch_assoc/array, of course).
---John Holmes...