Jump to content

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


Bradley99

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.