Pot Pot
Pot Pot

Reputation: 27

how to make dynamic year in select option

pls help me how could i make a dynamic year inside the select option. heres my code and this one gives me a result of separated year. how could i make the result just in one select option?

 $yrnw = date("Y");
 $lyr = 1;
$lstyr = $yrnw - $lyr ;
$sy = 10 + $yrnw;

 for($i=$yrnw; $i<$sy ; $i++){
$lst = $i -1;                   
echo "<tr><td>SY:</td></tr><tr><td><select name= 'sy'>
<option value=''>$lst-$i<br/></option>
"; } 

Upvotes: 0

Views: 127

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

Move the echo "<tr><td>SY:</td></tr><tr><td><select name= 'sy'> to before the for loop.

echo "<tr><td>SY:</td></tr><tr><td><select name= 'sy'>";
for ($i=$yrnw; $i<$sy ; $i++) {
    $lst = $i -1;                   
    echo "<option value=''>$lst-$i<br/></option>";
} 
 echo "</select></td></tr>";

Upvotes: 3

Related Questions