Jump to content

[SOLVED] Help with count query


mediabob

Recommended Posts

Hi, I am trying to count specific rows in the db and I can't get it right, here is what I am using:

 

$countShows = mysql_query("SELECT count(*) FROM rating WHERE itemid = '$file_id' AND ruserid = '$name' AND rcat = '$catname' ");
$count = mysql_result($countShows, 0, 0);

 

The variables and connection details are handled earlier in the script, I know the connection is OK because there is another query that works and I checked the variables and they are returning the correct value, but I get this error when I view the page:

 


Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/usr/public_html/ddd/ddd/page.php on line 105

 

This actually worked, but then stopped working for no reason, nothing was changed.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/86996-solved-help-with-count-query/
Share on other sites

OK when I tried to print the query it told me there was no database selected, so I played with it and finally got this to work

 

$query_countShows = "SELECT * FROM rating WHERE itemid = '$file_id' AND ruserid = '$name' AND rcat = '$catname'";
$countShows = mysql_query($query_countShows, $dload) or die(mysql_error());
$num_rows = mysql_num_rows($countShows);

 

Thanks for your help guys!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.