| | |
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: 12
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
Views: 719 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email emptydisplayvalue error explodefunction file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery keywords limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






