Re: Error on mysql_num_rows

From: Date: Thu, 20 Mar 2003 12:55:43 +0000
Subject: Re: Error on mysql_num_rows
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-140420@lists.php.net to get a copy of this message
Hi, Thursday, March 20, 2003, 10:44:33 PM, you wrote: ehhc> I've been trying to count records that match my query in MySQL using the ehhc> examples given in the on-line manual as well as the user comments and I'm ehhc> still getting the error: ehhc> Warning: mysql_num_rows(): supplied argument is not a valid MySQL result ehhc> resource. ehhc> Here's the code. ehhc> mysql_connect ($local_host, $local_user, $local_pass); ehhc> mysql_select_db ($local_db); ehhc> $result = mysql_query ("SELECT count(id) FROM listings WHERE agent = ehhc> '$agent' AND child = '0'"); ehhc> $rc = mysql_num_rows($result); ehhc> mysql_close(); ehhc> Is there something I'm missing here? I've tried using just about every ehhc> example in the on-line manual and get the same error. I can run other ehhc> queries just fine though. ehhc> Thanks, ehhc> Ed I would be guessing that there is a mysql error so put in some checking and echo mysql_error() Also count(id) will ever only return 1 row so you have to retrieve that to get the actual count. An easy way is like this if(!$result = mysql_query ("SELECT count(id) AS id_count FROM listings WHERE agent = '$agent' AND child = '0'")){ echo 'Oops : '.mysql_error(); }else{ $row = mysql_fetch_array($result); echo 'count = '.$row['id_count']; } -- regards, Tom

« previous php.general (#140420) next »