Create Month Drop-Down in PHP
Hi, guys. Welcome to my website. I have made so many tutorials related to PHP and PHP Framework, also I have made many tutorials of other programming languages. If you feel comfortable with our programming tutorial, please visit every programming tutorial and follow our website. You can Subscribe to our site using your Gmail account. Visit to get the latest programming tutorial: Datainflow Programming Tutorial.
Today, I am discussing a simple PHP tutorial. In this tutorial, I will show you, how to create a monthly dropdown system dynamically using simple PHP programming. I have created it on my web page without using any jQuery or JavaScript. I have used a simple for loop here. You can define in your web form page the common feature of a drop-down box of the month.
It will be very helpful when you submit a form with month value to store into the MySQL database. I will show you a beautiful Month Dropdown with auto-increment month value in the select dropdown list. The month drop-down select input box active the current month and displays all month names in the select input box.
When users select a month from the drop-down box, it gets the month value. You can store the month value in a variable and insert the month value into the database. For better understanding follow the example code.
The example code is here:
This is an example code for the current month to the end of the month dropdown.
<div class="col-md-6 col-sm-6 col-xs-12"> <select class="form-control" required="required" name="select_month"> <?php for ($i = 0; $i <= 12; ++$i) { $time = strtotime(sprintf('-%d months', $i)); $Monthdecimalvalue = date('m', $time); $MonthName = date('F', $time); printf('<option value="%s">%s</option>', $Monthdecimalvalue, $MonthName); } ?> </select> </div>
January to December month drop down in HTML using PHP, apply the below code.
<select name="select_month" class="form-control"> <option value=""> -- Choose -- </option> <?php for ($i = 1; $i <= 12; ++$i) { echo '<option value="'. date('F', mktime(0,0,0,$i)).'">'. date('F', mktime(0,0,0,$i)).'</option>'."\n"; } ?> </select>
If you want to create year dropdown list in PHP, please click the below link.