Forum Moderators: coopster
$sqly = "SELECT COUNT(*) FROM blah WHERE blah = $blah";
$yResult=mysql_query( $sqly , $db_connection );
Now when I try to echo the yResult I get the followign type of error:
Resource id #3
and not the count. I know this is simple but it is baffling me. I can get the number if I do a select and then count rows but that seems a bad way of doint it.
Regards
To retrieve the count just retrieve the first and only row returned by the query with any of the mysql_fetch_* methods.
Andreas
I have further query related to efficiency of code. Say I wish to print a list of subjects and I want to print a count for each record that has the related subject. The way I do it now is to loop the sql that is required to count and echo the number. This works but I need to know if this is the best way. It seems wasteful in that I make and break multiple db connections and run the SQL multiple times.
Could I do this with a group by.
Regards