Re: COUNT() returns 1, but should be 0
| From: | John W. Holmes | Date: | Mon, 22 Dec 2003 02:56:01 +0000 |
| Subject: | Re: COUNT() returns 1, but should be 0 | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-32149@lists.php.net to get a copy of this message | ||
Lew Mark-Andrews wrote:
I get a count of 1 for the number of visits ($visitcount) using my following code. It should be 0. ------------------- <snipped> code in check_visits.php $sql = "SELECT COUNT(visitdate) FROM cardlist GROUP BY visitdate"; $query = mysql_query($sql) or die("<br><br><div align='center'> Cannot query the database.<br><br>" . "MySQL Error No. " . mysql_errno() . " : <br><br>" . mysql_error() . "<br><br></div>"); $visitcount = mysql_num_rows($query); [snip]
echo "<p>Total number of users: $usercount</p>"; echo "<p>Total number of visits: $visitcount</p><br>"; // <--- Should be zero. </snipped>That's because you're displaying how many "rows" were returned from the query, not the value that COUNT() returns. A query with COUNT() is always going to return at least one row. $visitcount = mysql_result($query,0); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com