| | |
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 |
ajax apache api array beginner binary body broken cakephp checkbox class cms code cookies cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert interactive ip javascript job joomla js limit link login mail mediawiki menu mlm mobile msqli_multi_query multiple mycodeisbad mysql navigation oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion regex remote script search server sessions sms source space sql stored subdomain syntax system table tutorial unicode update upload url validator variable video web webapplications websitecontactform xml youtube






