Jim R Posted September 20, 2011 Share Posted September 20, 2011 I'm getting an invalid argument error for my While loop. I can't figure out why. $sql="SELECT * FROM schools ORDER BY class DESC,sectional ASC,team ASC"; $results = mysql_query($sql); while ($team = mysql_fetch_assoc($results)) { echo $team['school'] . '<br>'; } Here is the error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/******/public_html/hoosierhoopsmagazine.com/resources/sectional_assignments.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/ Share on other sites More sharing options...
AyKay47 Posted September 20, 2011 Share Posted September 20, 2011 your ORDER BY clause is invalid.. read thheree documentation Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270955 Share on other sites More sharing options...
Adam Posted September 20, 2011 Share Posted September 20, 2011 You know what they say about assumption being the mother of all f**k ups? Always check for errors when you execute a query: $results = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270956 Share on other sites More sharing options...
Jim R Posted September 20, 2011 Author Share Posted September 20, 2011 I've been looking at ORDER BY examples, and what I've found so far tells me to do it that way. I'll keep looking. Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270957 Share on other sites More sharing options...
Adam Posted September 20, 2011 Share Posted September 20, 2011 I can't actually see a fault with the ORDER BY, assuming the column names are correct. Check the error as I mentioned before... Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270958 Share on other sites More sharing options...
Jim R Posted September 20, 2011 Author Share Posted September 20, 2011 Adam, that was the error which was produced. Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270959 Share on other sites More sharing options...
AyKay47 Posted September 20, 2011 Share Posted September 20, 2011 perhaps I am misunderstanding the documentation.. debugging your query is always the first step.. using code like Adam posted.. once you receive an error it will make it easier to remedy this.. Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270961 Share on other sites More sharing options...
AyKay47 Posted September 20, 2011 Share Posted September 20, 2011 Adam, that was the error which was produced. post the error please Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270962 Share on other sites More sharing options...
Jim R Posted September 20, 2011 Author Share Posted September 20, 2011 I did. Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270963 Share on other sites More sharing options...
Jim R Posted September 20, 2011 Author Share Posted September 20, 2011 Even with Adam's code, it produces: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/jwrbloom/public_html/hoosierhoopsmagazine.com/resources/sectional_assignments.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270964 Share on other sites More sharing options...
AyKay47 Posted September 20, 2011 Share Posted September 20, 2011 okay i don't think you're understanding.. lets try something more simple.. $sql="SELECT * FROM schools ORDER BY class DESC,sectional ASC,team ASC"; $results = mysql_query($sql) or die(mysql_error()); while ($team = mysql_fetch_assoc($results)) { echo $team['school'] . '<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270965 Share on other sites More sharing options...
Jim R Posted September 20, 2011 Author Share Posted September 20, 2011 I am understanding. I put the exact code Adam told me to put, and that was what it produced, which is what I posted in the response above. Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270970 Share on other sites More sharing options...
Jim R Posted September 20, 2011 Author Share Posted September 20, 2011 As usual, it's something stupidly simple, like a typo. hschool instead of school. Thanks for your time guys. Sorry it wasn't even a code issue. Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270971 Share on other sites More sharing options...
AyKay47 Posted September 20, 2011 Share Posted September 20, 2011 As usual, it's something stupidly simple, like a typo. hschool instead of school. Thanks for your time guys. Sorry it wasn't even a code issue. not a problem.. Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1270984 Share on other sites More sharing options...
Adam Posted September 20, 2011 Share Posted September 20, 2011 I am understanding. I put the exact code Adam told me to put, and that was what it produced, which is what I posted in the response above. Yeah sorry for the confusion, I missed out E_USER_ERROR for the second parameter. If you didn't see the MySQL error though it's likely you have warning messages hidden. Quote Link to comment https://forums.phpfreaks.com/topic/247499-im-getting-an-invalid-argument-error-for-my-while-loop/#findComment-1271037 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.