unable to echo a dropdown box with php variables help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

unable to echo a dropdown box with php variables help!

Post by Mythic Fr0st »

Ok, im trying to echo the contents of the array '$inv' into a dropdown box... (an inventory system)

however it only shows $inv[$key] in the dropdown box, how can I get it to recognize the $inv variable?

code:

Code: Select all

?>
<form method="post" action="HomePIG.php">
<select name='inv'>
<php
foreach ($inv as $key => $shw)
{
echo '<option value=$inv[$key]>$inv$[key]</option>';
}
?>
</select>
</form>
thats currently what I have, can anyone help?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Read the manual on strings (particularly the part about the types of quotes and what they do).
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Re: unable to echo a dropdown box with php variables help!

Post by Begby »

Try it with double quotes like this, when its single quotes it doesn't evaluate variables.

Code: Select all

<form method="post" action="HomePIG.php">
<select name='inv'>
<?php
foreach ($inv as $key => $shw)
{
echo "<option value=\"{$inv[$key]}\">{$inv[$key]}</option>";
}
?>
Also, $inv[$key] is the exacty same as $shw in your example above.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Post by Mythic Fr0st »

Thanks alot... it worked
Post Reply