• All
  • Free Web Hosting
  • Category 2
gravatar

how to loop years in php?

 Create a drop down or a combo box and insert the code below:

Author: Kevern V.

 <?php
          echo "<select name='ins' id='ins' class='yearstyle' onchange=\"computeAge(this.value);\">";
          for($i=1950;$i<=date('Y');$i++){
           echo "<option value='" . $i . "'>" . $i . "</option>";

        }
        echo "<option value='select' selected>Year</option>";
           echo "</select>";
      ?>

//1950 is hard coded, depends on your starting year choice. just make sure that the present year is not hard coded so that it will change depends on the current year.