Jump to content

No output for pulldown menu


OriginalSunny

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??
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.