I think I've found my problem. The query does work if I place the exact
same code directly into my script but I had previously been calling it as
a function from an include file. It's working just great now.

Thanks,

Ed



On Thu, 20 Mar 2003, Tom Rogers wrote:

> 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
> 
> 
> -- 
> 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

Reply via email to