Bradley99 Posted June 24, 2012 Share Posted June 24, 2012 I've had this error before, but can't remember how I fixed it. I know it's happening because of the Query but i really can't see what wrong. <? $select_fighter = mysql_query("SELECT * FROM fighters WHERE promotion=UFC ORDER by id ASC"); while($the=mysql_fetch_object($select_fighter)){ ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/264695-warning-mysql_fetch_object-supplied-argument-is-not-a-valid-mysql-result-res/ Share on other sites More sharing options...
premiso Posted June 24, 2012 Share Posted June 24, 2012 Doing some error handling will help you diagnose the problem next time. For now, your issue lies with not putting a string in single quotes. $select_fighter = mysql_query("SELECT * FROM fighters WHERE promotion='UFC' ORDER by id ASC"); For better error handling that would tell you there is an error: $select_fighter = mysql_query("SELECT * FROM fighters WHERE promotion=UFC ORDER by id ASC") or trigger_error('Query Failed: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/264695-warning-mysql_fetch_object-supplied-argument-is-not-a-valid-mysql-result-res/#findComment-1356612 Share on other sites More sharing options...
Bradley99 Posted June 24, 2012 Author Share Posted June 24, 2012 Thanks, that works perfectly! Quote Link to comment https://forums.phpfreaks.com/topic/264695-warning-mysql_fetch_object-supplied-argument-is-not-a-valid-mysql-result-res/#findComment-1356616 Share on other sites More sharing options...
Bradley99 Posted June 24, 2012 Author Share Posted June 24, 2012 It is now calling them perfectly, BUT it calls ID #1 in the table format, but then just displays the other as plain text. Code: <table class="main" align"left" style='table-layout:fixed' cellpadding="2" cellspacing="0" rules="none" width="100%"> <col width=15> <col width=40> <col width=20> <col width=25> <tbody> <tr> <td colspan="4" align="left" class="TableHeading"> <b>Fighters</b></td> </tr> <tr> <td class="subtableheader" width="25%">ID:</td> <td class="subtableheader" width="25%">Name:</td> <td class="subtableheader" width="25%">Weight:</td> <td class="subtableheader" width="25%">Promotion:</td> </tr> <? $select_fighter = mysql_query("SELECT * FROM fighters WHERE promotion='UFC' ORDER by id ASC"); while($the=mysql_fetch_object($select_fighter)){ echo " <tr><td class='profilerow'>$the->id</td><td class='profilerow'>$the->name</td><td class='profilerow'>$the->weight</td><td class='profilerow'>$the->promotion</td> </tr>";?> </tbody> </table> Quote Link to comment https://forums.phpfreaks.com/topic/264695-warning-mysql_fetch_object-supplied-argument-is-not-a-valid-mysql-result-res/#findComment-1356625 Share on other sites More sharing options...
premiso Posted June 24, 2012 Share Posted June 24, 2012 You are missing the closing } for the while...surprised it displayed at all. Quote Link to comment https://forums.phpfreaks.com/topic/264695-warning-mysql_fetch_object-supplied-argument-is-not-a-valid-mysql-result-res/#findComment-1356628 Share on other sites More sharing options...
Bradley99 Posted June 24, 2012 Author Share Posted June 24, 2012 If i change it to this: <? $select_fighter = mysql_query("SELECT * FROM fighters WHERE promotion='UFC' ORDER by id ASC"); while($the=mysql_fetch_object($select_fighter)){ } echo " <tr><td class='profilerow'>$the->id</td><td class='profilerow'>$the->name</td><td class='profilerow'>$the->weight</td><td class='profilerow'>$the->promotion</td> </tr>";?> I get nothing atall, Nothing displays, Just an empty table. Quote Link to comment https://forums.phpfreaks.com/topic/264695-warning-mysql_fetch_object-supplied-argument-is-not-a-valid-mysql-result-res/#findComment-1356634 Share on other sites More sharing options...
Barand Posted June 24, 2012 Share Posted June 24, 2012 it would help if you had the echo within the while block. Quote Link to comment https://forums.phpfreaks.com/topic/264695-warning-mysql_fetch_object-supplied-argument-is-not-a-valid-mysql-result-res/#findComment-1356687 Share on other sites More sharing options...
Bradley99 Posted June 24, 2012 Author Share Posted June 24, 2012 Yep, I seem to be rather stupid. Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/264695-warning-mysql_fetch_object-supplied-argument-is-not-a-valid-mysql-result-res/#findComment-1356689 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.