Hi, I have been trying for the past 2days to try and figure what I need to do have the date automatically selected in the pull down menu.
This is for a 'admin' section where a players date of birth($dob) are held.
They are inputting via three pull down menus.. one for the day, one for the month and one for the year, these are then sent to the database in this format $year$month$day for example a player born on the 22nd January 1973 is stored as 19730122.
Well anyway this is code I use:
$dob = $myrow[dob]
$dob is also a field in the table as seen above.
$dob = $dob[year];
$dob .= $dob[month];
$dob .= $dob[day];
list ($dob[month], $dob[day], $dob[year]) = split ('[-]', $dob);
(The above is meant to split the date up after the - tags.. i.e. year-month-day (4-2-2)
print "<select name=\"dob[day]\">";
$i = 1;
while ($i < 32) :
print "<option value=\"";
if ($i < 10) {print "0";}
print "$i\" ";
if ($dob[year] == $i) {print " selected";}
print ">$i</option>\n";
$i++;
endwhile;
print "</select>
In the above section what I have tried to do is:
if ($dob[year] == $i) {print " selected";}
However this does not work and it merely selects "1" by default from the pull down.. the other two pull down menus also do this.. so I end up with the following date:
01-01-1950
<select name=\"dob[month]\">";
$i = 1;
while ($i < 13) :
print "<option value=\"";
if ($i < 10) {print "0";}
print "$i\" ";
if ($dob[month] == $i) {print " selected";}
print ">$i</option>\n";
$i++;
endwhile;
print "</select>
<select name=\"dob[year]\">";
$i = 1970;
while ($i < 1990) :
print "<option value=\"$i\" ";
if ($dob[year] == $i) {print " selected";}
print ">$i</option>\n";
$i++;
endwhile;
print "</select>";
?>
Any help would be great! 🙂