I want to create a drop down menu in php for my local host and tried following, But using it The drop down menu appears, but is blank, and has no options.
<?php
session_start();
//if the session data has been set, then the variable $sv_02 is defined
//as the data held in the session under that name, otherwise it is blank
if (isset($_SESSION['sv_02'])) {$sv_02=$_SESSION['sv_02'];} else {$sv_02="";}
//define the array
$dm_sv_02 = array('-Year','-2012','-2011','-2010','-2009');
//create the function
function dropdown($dropdownoptions, $session_data)
{
foreach($dropdownoptions as $dropdownoption){
if($session_data == $dropdownoption){
echo '<option value="' . $dropdownoption . '" selected>' . $dropdownoption . '</option>';
} else {
echo '<option value="' . $dropdownoption . '">' . $dropdownoption . '</option>';
}
}
}
//echo the HTML needed to create a drop down, and populate it with
//the function which should create the <option> elements
echo '<select name="sv_02">';
dropdown($dm_sv_02, $sv_02);
echo '</select>';
?>
Create a Dropdown menu in Php
Moderator: General Moderators
-
liveproject101
- Forum Newbie
- Posts: 1
- Joined: Tue Apr 09, 2013 6:23 am
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Create a Dropdown menu in Php
Are there any error, notice or warning messages displayed when you run the script? the script itself works, displays the dropdown menu with 'Year' and then the year values.
try using the php code button; it makes the code easier to read
try using the php code button; it makes the code easier to read
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering