widget Posted July 1, 2011 Share Posted July 1, 2011 Heres a doosey - well for me anyway. I have a cron file to clear out high scores and award a trophy to the top 3 players. Now if I run the Bubble Pop cron job (top code) it works fine however if I run the Pyramid one(bottom code) it throws back an error at me Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/kabooc/public_html/ghetto_cron.inc.php on line 384 Line 384 is if(mysql_num_rows($result)) Both are the exact same code bar the second one has a WHERE clause. if ($run['Bubblepop']) { $sql_query = "SELECT username,MAX(score) as total FROM highscores_bubblepop GROUP BY username ORDER BY 'total' DESC LIMIT 0 , 3"; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { $x =110; while($row = mysql_fetch_row($result)) { mysql_query("INSERT INTO trophy (user_name, trophy_id) VALUES ('$row[0]','$x')"); mysql_query("INSERT INTO records (record_type, record_entry, userid) VALUES ('Bubble Pop Trophy','$row[0] was awarded a $x trophy','1')"); $x ++; } } mysql_query("DELETE FROM highscores_bubblepop"); } if ($run['Trophy Pyramid Solitaire']) { $sql_query = "SELECT username,MAX(score) as total FROM highscores WHERE gameID = '106' GROUP BY username ORDER BY 'total' DESC LIMIT 0 , 3"; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { $x =101; while($row = mysql_fetch_row($result)) { mysql_query("INSERT INTO trophy (user_name, trophy_id) VALUES ('$row[0]','$x')"); mysql_query("INSERT INTO records (record_type, record_entry, userid) VALUES ('Trophy Pyramid Solitaire','$row[0] was awarded a $x trophy','1')"); $x ++; } } } I have looked through google and most errors I find the solution is to... double check database tables - done check spelling - done check connection - done is there an alternative way to do what I am trying and what is it? or is there some sort of blatantly obvious error and im just not seeing it? Quote Link to comment https://forums.phpfreaks.com/topic/240872-warning-mysql_num_rows-tearing-hair-out/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 1, 2011 Share Posted July 1, 2011 Your code is not checking if the query executed without any errors before attempting to access the data from the query. If you use mysql_error() in some error checking and error reporting/logging logic, it will tell you why the query is failing. Are you debugging this by browsing to the file to see the errors or are you running this as a cron job and checking the php errors in the log file? Quote Link to comment https://forums.phpfreaks.com/topic/240872-warning-mysql_num_rows-tearing-hair-out/#findComment-1237260 Share on other sites More sharing options...
widget Posted July 1, 2011 Author Share Posted July 1, 2011 im running the cron job and refreshing the page as it happens and getting the error Quote Link to comment https://forums.phpfreaks.com/topic/240872-warning-mysql_num_rows-tearing-hair-out/#findComment-1237262 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.