Page 1 of 1
can i loop the values that will display in the dropdown menu
Posted: Thu Mar 04, 2004 1:34 am
by softsolvers
hello i want to use loop in the drop down menu,i.e. i will like to display the
list of years like 1900 to 2004 ,how can i save the size of the code by implementing the loop in this menu
Posted: Thu Mar 04, 2004 1:37 am
by andre_c
like this:
Code: Select all
echo "<select name='some_name'>\n";
for ($i=1900; $i<=2004; $i++) {
echo "<option value='$i'>$i</option>\n";
}
echo "</select>\n";
I hope that helps
Posted: Thu Mar 04, 2004 1:38 am
by markl999
Or..
Code: Select all
foreach(range(1900, 2004) as $year){
echo '<option value="'.$year.'">'.$year.'</option>';
}
Posted: Thu Mar 04, 2004 1:43 am
by andre_c
nice way to use a foreach with the range function. I never though of that. cool.