Jump to content

Archived

This topic is now archived and is closed to further replies.

OriginalSunny

No output for pulldown menu

Recommended Posts

Hi i am having a problem with my output. I am trying to create a pull down menu which gives the user a list of options to choose from. I have used the code below:

[b].inc file[/b]
[i]$food = array( "chips" => "Vodaphone",
"beans" => "o2",
"bacon" => "Orange",
"eggs" => "Tmobile",
);

<table border="0" cellpadding="5" cellspacing="0">

echo "<tr><td style=\"text-align: right;
font-weight: bold\">Select</td>
<td><select name='food'>";
foreach($food as $field => $value)
{
echo "<option value='$field'";
echo ">$value\n";
}
echo "</select>";

<tr><td align="center" colspan="2">
<input type="submit"
value="Submit"></td></tr>[/i]

[b].php file[/b]
[i] switch (@$_GET['do'])
{
case "new":
$connect = connect_to_db("conn.inc");

$sql = "Select name from stock where
food='$food'";

$result = mysql_query($sql,$connect)
or die("sql: ".mysql_error($connect));

$price = mysql_result($result,0,0);
echo "$price";

break;

default:
include("tariff.inc");
}[/i]

The output for this is not how i want it. There is a pulldown, but this pulldown contains nothing in it. This is also displayed on the screen:

array( "chips" => "Chips",
"beans" => "Beans",
"bacon" => "Bacon",
"eggs" => "Eggs",

);

These options should be comming out on the pulldown rather than just be printed on the screen as above. What am i doing wrong??

Share this post


Link to post
Share on other sites
You didn't close "<option>" when looping.

Share this post


Link to post
Share on other sites
Use the opening and closing php tags in the appropriate places. Example:

[code]
<table border="0" cellpadding="5" cellspacing="0">

<?PHP
$food = array( "chips" => "Vodaphone",
"beans" => "o2",
"bacon" => "Orange",
"eggs" => "Tmobile"
);

echo "<tr><td style=\"text-align: right;
font-weight: bold\">Select</td>
<td><select name='food'>";
foreach($food as $field => $value)
{
echo "<option value='$field'";
echo ">$value\n";
}
echo "</select>";

?>

<tr><td align="center" colspan="2">
<input type="submit"
value="Submit"></td></tr>
[/code]

I hope you remember to select a DB after connecting to one in your connect_to_db() function.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.