Max, PHP.net says: "Calls to mysql_result() should not be mixed with calls to other functions that deal with the result set. "
I would use mysql_fetch_array which they say is MUCH faster, example of how you could use it: <?php mysql_connect($host, $user, $password); mysql_select_db("database"); $sqlinfo = "SELECT username, COUNT(username) as count FROM usertable WHERE > username='me' GROUP BY username"; $number_of_rows=mysql_num_rows($sqlinfo) if($number_of_rows != '0') { while ($row = mysql_fetch_array($sqlinfo)) { echo "count: ".$row["count"]."<br>\n"; echo "username: ".$row["username"]."<br>\n"; } } mysql_free_result($result); ?> -----Original Message----- From: David Robley [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 05, 2002 8:29 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: PHP and mySQL In article <180f01c1c403$2ac62820$[EMAIL PROTECTED]>, [EMAIL PROTECTED] says... > 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 Assuming that your username is unique, I would expect that you would only get one row returned from that query? In which case much of your SQL is redundant. Anyhow, your $count line reads the first row of the result, then sets the pointer to the next row in the result set - if this is empty (ie only one row retrieved) then you will get a null result for your while loop as there are no more results to display. Try using mysql_data_seek to return the pointer to row 0 before your while loop. -- David Robley Temporary Kiwi! Quod subigo farinam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php