| | |
Need Help with converting an ID to a Name
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2007
Posts: 11
Reputation:
Solved Threads: 0
php Syntax (Toggle Plain Text)
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:
php Syntax (Toggle Plain Text)
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.
Last edited by jtmcgee; Oct 7th, 2007 at 5:50 pm.
try this, it might work.
PHP Syntax (Toggle Plain Text)
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);
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 );
Last edited by johny_d; Oct 8th, 2007 at 5:39 pm.
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.
![]() |
Similar Threads
- converting vrml 1.0 to 2.0 (Computer Science)
- Converting lowercase to capitals (Java)
- Converting Excel to Mysql (MySQL)
- Converting Bytes to MB? (Visual Basic 4 / 5 / 6)
- converting base class to dervived class (C)
- Converting from VB code to C (C)
- Converting Access Forms to PHP Forms (PHP)
Other Threads in the PHP Forum
- Previous Thread: Paging Problem
- Next Thread: Parse html
| Thread Tools | Search this Thread |
# .htaccess 5.2.10 access alexa apache api array beginner broken cakephp checkbox class clean clients cms code convert cron curl database date directory display dissertation dropdown dynamic echo$_get[x]changingitintovariable... email encode error fairness file folder form forms function functions google hack href htaccess html htmlspecialchars image include indentedsubcategory ip javascript joomla legislation limit link local login mail memberships menu methods multiple multipletables mysql mysqlquery network newsletters oop open passwords paypal pdf persist php provider query radio random redirect remote script search secure server sessions simple sockets source space spam sql system table tutorial upload url user variable video voteup web youtube






