•
•
•
•
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
![]() |
| |
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Rep Power: 0
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.
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
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]."!";
}•
•
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation:
Rep Power: 2
Solved Threads: 4
•
•
•
•
$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.
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- converting vrml 1.0 to 2.0 (Computer Science and Software Design)
- 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


Hybrid Mode