943,885 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 802
  • PHP RSS
Oct 7th, 2007
0

Need Help with converting an ID to a Name

Expand Post »
php Syntax (Toggle Plain Text)
  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:

php Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jtmcgee is offline Offline
13 posts
since Oct 2007
Oct 7th, 2007
0

Re: Need Help with converting an ID to a Name

try this, it might work.

PHP Syntax (Toggle Plain Text)
  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. }
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Oct 8th, 2007
0

Re: Need Help with converting an ID to a Name

Quote ...
$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
Quote ...
$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.
Reputation Points: 33
Solved Threads: 7
Junior Poster in Training
johny_d is offline Offline
92 posts
since May 2007
Oct 8th, 2007
0

Re: Need Help with converting an ID to a Name

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Paging Problem
Next Thread in PHP Forum Timeline: Parse html





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC