Create year dropdown list using a loop in PHP:
Create year dropdown list using for loop in PHP: in PHP websites create a year dropdown list and get year value dynamically using PHP programming language.
In your websites use a range of year drop-down box. You can define in your web form page common feature of the drop-down box of year. Using for loop create a year dropdown list dynamically in your website.
This tutorial helps you to create two types of year dropdown list in your websites. obviously, the dropdown list will be dynamically on your page.
- Auto increment year dropdown list:
- Auto-decrement year dropdown list:
So let’s start to create dynamically year dropdown list using for loop in PHP.
Auto increment year dropdown list:
This list first option display current year and next display year auto increment.
Example:
<select id="year" name="year" class="form-control"> <option></option> <?php $y=(int)date('Y'); ?> <option value="<?php echo $y;?>" selected="true"><?php echo $y;?></option> <?php $y++; for(; $y<'2024'; $y++) { ?> <option value="<?php echo $y;?>"><?php echo $y;?></option> <?php }?> </select>
Auto-decrement year dropdown list:
Example:
<select id="year" name="year" class="form-control"> <option></option> <?php $y=(int)date('Y'); ?> <option value="<?php echo $y;?>" selected="true"><?php echo $y;?></option> <?php $y--; for(; $y>'2012'; $y--) { ?> <option value="<?php echo $y;?>"><?php echo $y;?></option> <?php }?> </select>
Related posts
You have to create the all drop down list on this that was using among the all loop at PHP language. I have to get the all frictions about the all languages on it that was on blueskyresumes.com this was the site that have the all fields available on this along with the all aspects on this.