I'm trying to create a query that searches between dates. There is the begin date fields which are easy, I just set to the earliest date that the records will go, in this case January 1, 1998. But for the end date, I want it to preselect the current month and current date.
It works fine, except the month is not displaying the current month. Here is the code I came up with... I have a feeling it may be a problem where it compares the current month. Why wouldn't it work since I'm pulling out only the month value to use to compare?
Any ideas or suggestions is greatly appreciated.
Thanks,
-T
It works fine, except the month is not displaying the current month. Here is the code I came up with... I have a feeling it may be a problem where it compares the current month. Why wouldn't it work since I'm pulling out only the month value to use to compare?
Code:
<?php
$yr = 1998;
$c_yr=date('Y');
$slctbx = '';
while ($yr <= $c_yr) {
if($yr == $c_yr) {
$slctbx .= "<option value=\"".$yr."\" SELECTED>".$yr."</option>\n";
$yr++;
} else {
$slctbx .= "<option value=\"".$yr."\">".$yr."</option>\n";
$yr++;
}
}
$mth = 01;
$emth = 12;
$cmth=date('m');
$slctbx2 = '';
while ($mth <= $emth) {
if($mth == $cmth) {
$slctbx2 .= "<option value=\"".$mth."\" SELECTED>".$mth."</option>\n";
$mth++;
} else {
$slctbx2 .= "<option value=\"".$mth."\">".$mth."</option>\n";
$mth++;
}
}
echo "Month:<select name='month'>$slctbx2</select>Year:<select name='yr'>$slctbx</select>";
?>
Any ideas or suggestions is greatly appreciated.
Thanks,
-T