mediabob Posted January 21, 2008 Share Posted January 21, 2008 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 More sharing options...
mmarif4u Posted January 21, 2008 Share Posted January 21, 2008 Try this: $countShows = mysql_query("SELECT count(*) FROM rating WHERE itemid = '$file_id' AND ruserid = '$name' AND rcat = '$catname' "); $num_rows = mysql_num_rows($countShows); echo $num_rows; Link to comment https://forums.phpfreaks.com/topic/86996-solved-help-with-count-query/#findComment-444845 Share on other sites More sharing options...
mediabob Posted January 21, 2008 Author Share Posted January 21, 2008 get the same error, says mysql_num_rows is not a valid result resource Link to comment https://forums.phpfreaks.com/topic/86996-solved-help-with-count-query/#findComment-444847 Share on other sites More sharing options...
mmarif4u Posted January 21, 2008 Share Posted January 21, 2008 $countShows = mysql_query("SELECT * FROM rating WHERE itemid = '$file_id' AND ruserid = '$name' AND rcat = '$catname' "); $num_rows = mysql_num_rows($countShows); echo $num_rows; Link to comment https://forums.phpfreaks.com/topic/86996-solved-help-with-count-query/#findComment-444850 Share on other sites More sharing options...
mediabob Posted January 21, 2008 Author Share Posted January 21, 2008 ??? still same error :-\ Link to comment https://forums.phpfreaks.com/topic/86996-solved-help-with-count-query/#findComment-444854 Share on other sites More sharing options...
mmarif4u Posted January 21, 2008 Share Posted January 21, 2008 can u show us the full code. Link to comment https://forums.phpfreaks.com/topic/86996-solved-help-with-count-query/#findComment-444856 Share on other sites More sharing options...
pdkv2 Posted January 21, 2008 Share Posted January 21, 2008 Do one thing try to print the query, i guess the query must be having the problem. Link to comment https://forums.phpfreaks.com/topic/86996-solved-help-with-count-query/#findComment-444858 Share on other sites More sharing options...
mediabob Posted January 21, 2008 Author Share Posted January 21, 2008 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! Link to comment https://forums.phpfreaks.com/topic/86996-solved-help-with-count-query/#findComment-444881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.