Jump to content

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result res


Recommended Posts

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

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());

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>

 

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.