emtec Posted October 22, 2009 Share Posted October 22, 2009 when i try to count rows from an SQL select i get an warning $countviews = mysql_query("SELECT * FROM viewed WHERE sfw = '0' AND cookieid = $id"); $num_rows_viewed = mysql_num_rows($countviews); Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ******.php on line 58 anybody an idea why this is? Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/ Share on other sites More sharing options...
Daniel0 Posted October 22, 2009 Share Posted October 22, 2009 Are you sure your query runs? If it fails, mysql_query() will return false, which is not a valid MySQL resource. Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/#findComment-941901 Share on other sites More sharing options...
trq Posted October 22, 2009 Share Posted October 22, 2009 You should check your query actually succeeds first (its not). if ($countviews = mysql_query("SELECT * FROM viewed WHERE sfw = '0' AND cookieid = $id")) { $num_rows_viewed = mysql_num_rows($countviews); // rest of code } Where is $id defined? Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/#findComment-941902 Share on other sites More sharing options...
emtec Posted October 22, 2009 Author Share Posted October 22, 2009 the $id is defined somwhere else in the code, i verified that there isone, an i also tried to run that sql and dint recieve any errors Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/#findComment-941904 Share on other sites More sharing options...
JAY6390 Posted October 22, 2009 Share Posted October 22, 2009 You should also use quotes around the cookie id "SELECT * FROM viewed WHERE sfw = '0' AND cookieid = '$id'" And I really hope you've sanitized your data in $id before just throwing it into an SQL query or you could have some nasty results Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/#findComment-941910 Share on other sites More sharing options...
Daniel0 Posted October 22, 2009 Share Posted October 22, 2009 Not if it's a numeric value. Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/#findComment-941912 Share on other sites More sharing options...
JAY6390 Posted October 22, 2009 Share Posted October 22, 2009 It will still work regardless of being a numerical value or not Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/#findComment-941916 Share on other sites More sharing options...
Daniel0 Posted October 22, 2009 Share Posted October 22, 2009 I was talking about this part: You should also use quotes around the cookie id You don't need to do that. It's just redundant. Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/#findComment-941917 Share on other sites More sharing options...
emtec Posted October 22, 2009 Author Share Posted October 22, 2009 its a numerical value and its checked that it is an actual numerical value Quote Link to comment https://forums.phpfreaks.com/topic/178594-sql-num_rows-problem/#findComment-941920 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.