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

Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

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.