PHP Magic Book – Free PHP Scripts, Tutorials and Downloads, PHP AtoZ Reloaded, free php tutorials, free php downloads, php scripts, PHP tips

Auto Populate Years Range In PHP

In forms its better approach to populate years drop down list rather then writing down every year manually. This script will ask you starting year and rest of years up till latest year it will populate for you.

<?php
$currentYear = date("Y");
$years = range ($currentYear, 1900);
echo '<select>';
foreach ($years as $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
?>

Download Script

  • Share/Bookmark
Tags: , ,
Posted in: Form, Useful Scripts
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Related Posts




Post a Comment

  Subscribe Via RSS
  Subscribe Via Email