Jump to content


Photo

No output for pulldown menu


  • Please log in to reply
2 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 26 March 2006 - 01:34 AM

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:

.inc file
$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>


.php file
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");
}


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??

#2 azuka

azuka
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts
  • LocationNigeria

Posted 26 March 2006 - 01:43 AM

You didn't close "<option>" when looping.

Given enough eyeballs all bugs are shallow. My Website

#3 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 26 March 2006 - 01:49 AM

Use the opening and closing php tags in the appropriate places. Example:

<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>

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users