Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: for loop and birthday date

Tags:

php

I have a little problem

birthday´s get stored as DATE in the MySQL database.

DATE is 00-00-00

and now when i make the select options, i did it with a for loop:

<?php
$month_names = array("januar", "februar", "marts", "april", "maj", "juni", "juli", "august", "september", "oktober", "november", "december");
for ($i=1; $i<=12; $i++) {
    echo "<option ";
    if ($i == $month) {
        echo "selected=\"selected\" ";
    }
    echo "value=\"$i\">", $month_names[$i-1], "</option>\n";
}
?> 

This works, but gives me 1,2,3,4,5,6,7,8,9,10,11,12 as values.

I need to have it like this 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12.

How can i do this?

like image 786
Karem Avatar asked Jul 16 '26 00:07

Karem


1 Answers

Replace the 7th line with the following:

printf("value=\"%02d\">%s</option>\n", $i, $month_names[$i-1]);