Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Dropdown menu in Php

General discussions related to php

Moderators: macek, egami, gesf

Dropdown menu in Php

Postby liveproject101 » Sun Apr 21, 2013 8:35 pm

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>';
?>
Live Project Training
liveproject101
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Apr 08, 2013 11:31 pm

Re: Dropdown menu in Php

Postby johnj » Sun Apr 21, 2013 10:37 pm

print the array $dm_sv_02 and the variable $sv_02 and see if it has value etc
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP General

Who is online

Users browsing this forum: landi and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron