User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,534 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,030 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 486 | Replies: 3
Reply
Join Date: Oct 2007
Posts: 4
Reputation: jtmcgee is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jtmcgee jtmcgee is offline Offline
Newbie Poster

Help Need Help with converting an ID to a Name

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Need Help with converting an ID to a Name

  #2  
Oct 7th, 2007
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]."!";
 
		}
Reply With Quote  
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
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

  #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  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Need Help with converting an ID to a Name

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:42 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC