if( $rand_num <= $chance )
		{
			//$item_id = mysql_query("SELECT `item` FROM `creatures` WHERE id = '$id_creature'");
			$foo =& creature_stats( item, $id_creature );
			
			$item_query = mysql_query("SELECT * FROM items WHERE id = '$foo'") or ('$item_query');

			$item = mysql_fetch_array($item_query);

			echo"You got an ".$item."!";

		}

Creature Stats Function:

function &creature_stats($what_stat, $id) 
{
$mysql_query=mysql_query("SELECT * FROM `creatures` WHERE `id` = '$id'");
$info=mysql_fetch_array($mysql_query);
return $info[$what_stat];
}

I need help getting it to echo $item

It justs puts out nothing.

try this, it might work.

if( $rand_num <= $chance )
		{
			$item_id = mysql_query("SELECT `item` FROM `creatures` WHERE id = '$id_creature'");
			$foo =& creature_stats( item, $id_creature );
 
			$item_query = mysql_query("SELECT * FROM items WHERE id = '$foo'") or ('$item_query');
 
			$item = mysql_fetch_row($item_query);
 
			echo"You got an ".$item[0]."!";
 
		}

$item = mysql_fetch_array($item_query);

means $item is an array an you cannot put an array in an echo statement; this is why you get nothing.
You need to use $item in your "echo...."
You also have a sintax error: in

$foo =& creature_stats( item, $id_creature );

since item is a variable, it needs a $ sign in front; this is a very good reason why you get a blank nothing :)

sorry i overlooked that sintax error. wow i can't believe i missed that. also, before posting the code i did i should of asked the question; "Will the query ever return more than one result?". i figured there would only be one result and my way would work perfectly, but if more than one is returned you would need to use johny_d's way.

This article has been dead for over six months. Start a new discussion instead.