Jump to content

rogue while loop not filling variables from sql fetch array


Sabmin

Recommended Posts

This is really blowing my mind... the code is as follows the table, the column names everything is right and contains information but the variables aren't being filled... I don't get it... Anyone have any ideas or options I might not have thought of for debugging?

 

                        $item_name = ("SELECT * FROM items WHERE id = '$grab_item'");
		$que_items = mysql_query($item_name);
		while ($item_todel = mysql_fetch_array($que_items, MYSQL_BOTH)) {
			$name = $item_todel['name'];
			$desc = $item_todel['desc'];
		}
			echo ($name . "<br>" . $desc . "<br>" . $grab_item);

 

the only variable thats set is grab_item, fetch_array throws no errors, if I plug in the query straight to the sql I get all the proper information... It's just not filling the two variables....

Anyone have any ideas or options I might not have thought of for debugging?

 

Not hard considering there is no error trapping / debugging in your code at all.

 

Are you expecting more than one result? If so, you will need to do the echo'ing within the while loop. If your not, then you don't even need a while loop.

 

$sql = "SELECT name, `desc` FROM items WHERE id = '$grab_item'";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      $name = $row['name'];
      $desc = $row['desc'];
      echo $name . "<br>" . $desc . "<br>" . $grab_item;
    }
  } else {
    echo "No results found";
  }
} else {
  trigger_error(mysql_error() . "<br />$sql");
}

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.