I have a date of birth, and when the user is over Feb (02), the days should go only to 29. As you can see I'm using $month="1" just to test it. I'm supposed to use PHP only, no JavaScript or anything else. How would i go about making that?
<?php
$month="1"; // <-- currently using this to make it 29,30 or 31 days
print "<select name='day'>";
if ($month==1){
for ($i=0; $i<=28; $i++)
{
$day = 1 + $i;
print "<option value = $day>" . $day ."</option>";
}
}
if ($month==2){
for ($i=0; $i<=29; $i++)
{
$day = 1 + $i;
print "<option value = $day>" . $day ."</option>";
}
}
print "</select>";
print "<select name='month'>";
for ($i=0; $i<=11; $i++)
{
$month = 1 + $i;
print "<option value = $month>" .$month ."</option>";
}
print "</select>";
?>
$month == 1not$month =="1".Otherwise it is an string.$month == 1and$month == "1"to be the same.$month === 1and$month === "1"are different.true:$month == "1 foo bar". If he had used the strict comparison ($month === x) however, it would be a different story.switchstatement instead of all thoseifstatements. It won't change the functionality, but it will clean up your code a bit.$monthand value of number of days in that month and use just 1 piece of code likeprint "<select name='day'>"; for ($day=1; $day<=$n_days[$month]; $day++) print "<option value='$day'>$day</option>"; print "</select>";