Need Help with converting an ID to a Name

Reply

Join Date: Oct 2007
Posts: 11
Reputation: jtmcgee is an unknown quantity at this point 
Solved Threads: 0
jtmcgee jtmcgee is offline Offline
Newbie Poster

Need Help with converting an ID to a Name

 
0
  #1
Oct 7th, 2007
  1. if( $rand_num <= $chance )
  2. {
  3. //$item_id = mysql_query("SELECT `item` FROM `creatures` WHERE id = '$id_creature'");
  4. $foo =& creature_stats( item, $id_creature );
  5.  
  6. $item_query = mysql_query("SELECT * FROM items WHERE id = '$foo'") or ('$item_query');
  7.  
  8. $item = mysql_fetch_array($item_query);
  9.  
  10. echo"You got an ".$item."!";
  11.  
  12. }

Creature Stats Function:

  1. function &creature_stats($what_stat, $id)
  2. {
  3. $mysql_query=mysql_query("SELECT * FROM `creatures` WHERE `id` = '$id'");
  4. $info=mysql_fetch_array($mysql_query);
  5. return $info[$what_stat];
  6. }

I need help getting it to echo $item

It justs puts out nothing.
Last edited by jtmcgee; Oct 7th, 2007 at 5:50 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Need Help with converting an ID to a Name

 
0
  #2
Oct 7th, 2007
try this, it might work.

  1. if( $rand_num <= $chance )
  2. {
  3. $item_id = mysql_query("SELECT `item` FROM `creatures` WHERE id = '$id_creature'");
  4. $foo =& creature_stats( item, $id_creature );
  5.  
  6. $item_query = mysql_query("SELECT * FROM items WHERE id = '$foo'") or ('$item_query');
  7.  
  8. $item = mysql_fetch_row($item_query);
  9.  
  10. echo"You got an ".$item[0]."!";
  11.  
  12. }
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 68
Reputation: johny_d is an unknown quantity at this point 
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: Need Help with converting an ID to a Name

 
0
  #3
Oct 8th, 2007
$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['name_of_mysql_column'] 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
Last edited by johny_d; Oct 8th, 2007 at 5:39 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Need Help with converting an ID to a Name

 
0
  #4
Oct 8th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC