How to use html SELECT with While loop?

<label for="year">Year:</label>
    <select name="year" id="year">
    <?php
        $thisyear = date('Y');
        $limit = $thisyear + 5;
        while ($thisyear <= $limit){
            echo "<option value='$thisyear'></option>";
            $thisyear++;
        }
    ?>
    </select>

I am not getting the year in the drop down menu, how could I get it?

You’re omitting to echo the year between the <option> and </option> tags methinks.

1 Like

hmm… but without echoing it doesn’t display, can you do the modification of that line?.

IN view source, it is showing me right

<option value='2017'></option>
<option value='2018'></option>
<option value='2019'></option>
<option value='2020'></option>
<option value='2021'></option>
<option value='2022'></option>
    </select>
echo "<option value='$thisyear'>$thisyear</option>";
1 Like

Damn, this is hard to find lol… Thanks pal.:biggrin:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.