PHP and mySQL
| From: | Max Mouse | Date: | Tue, 05 Mar 2002 05:04:01 +0000 |
| Subject: | PHP and mySQL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-87222@lists.php.net to get a copy of this message | ||
I have a little problem when trying to count the number of results returned
in a mysql query. I was using mysql_num_rows() to do it with no problems,
but this isn't as quick as using mySQL's COUNT(*), or so I have been told so
I swtiched. Here's a snipit of the code...
$sqlinfo = "SELECT username, COUNT(username) as count FROM usertable WHERE
username='me' GROUP BY username";
$sqlresult = mysql_query($sqlinfo)
or die(mysql_error());
$count = mysql_result($sqlresult,0,"count");
if ($count <= 0) {
....FAILED....
} else {
while ($row = mysql_fetch_array($sqlresult)) {
$username = $row['username'];
}
}
The count value is set correctly but: when the while() loop is
executed...no values are set (there are a lot more, but I shortened it for
spaces sake). So, $username is null. If I remove the $count line, it
works....any suggestions?
Max