Dropdown menu in Php

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

<snip />

I tested your code and it works fine for me. It outputs (I added line breaks for readability):

<select name="sv_02">
<option value="-Year">-Year</option>
<option value="-2012">-2012</option>
<option value="-2011">-2011</option>
<option value="-2010">-2010</option>
<option value="-2009">-2009</option>
</select>

Works fine for me.

Alternative (taking the echo out of the function):

<?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)
{
     $str='';
    foreach($dropdownoptions as $dropdownoption){
        if($session_data == $dropdownoption){
            $str .= '<option value="' . $dropdownoption . '" selected>' . $dropdownoption . '</option>';
        } else {
            $str .= '<option value="' . $dropdownoption . '">' . $dropdownoption . '</option>';
        }
        $str .= "\
";
    }
    return $str;
}

//echo the HTML needed to create a drop down, and populate it with 
//the function which should create the <option> elements
?>

<form>
<select name="sv_02">
<?php
echo dropdown($dm_sv_02, $sv_02);
?>
</select>
</form>

But … is this really just a SPAM post? Otherwise why have you included a link in your post?

[ot]

Taken care of, in the future, please feel free to use the Report button (red flag) on the offending post.[/ot]

Off Topic:

I didn’t want to waste moderator time unnecessarily by reporting, so I was giving the OP the benefit of the doubt by asking first. :slight_smile: