OriginalSunny Posted March 26, 2006 Share Posted March 26, 2006 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?? Quote Link to comment Share on other sites More sharing options...
azuka Posted March 26, 2006 Share Posted March 26, 2006 You didn't close "<option>" when looping. Quote Link to comment Share on other sites More sharing options...
toplay Posted March 26, 2006 Share Posted March 26, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.