Forum Moderators: open
I cannot help you with the interactive interface (the form) but I can tell you that most databases have comparison functions and operators specifically for handling date comparison. The BETWEEN comparison is the likely solution in this case. Have a look in the Access Help for that keyword and hopefully there are examples.
The following uses mysql queries for example, alter accordingly to be compatible with MSsql/Access (should be nearly identical.)
You write some routine/function that generates date lists in the programming language of your choice. So
$startList = date_list('start_date');
$endList = date_list('end_date');
So in your form, you just need to do:
$output .= "<strong>Orders between</strong> $startDate <strong>and:</strong> $endDate";
So the "date_list" function/subroutine would return three lists (each.) In the function, you append the select name with _day, _month, _year:
<select name="start_date_month" id="start_date_month">....
<select name="start_date_day" id="start_date_day">....
<select name="start_date_year" id="start_date_year">....
<select name="end_date_month" id="end_date_month">....
<select name="end_date_day" id="end_date_day">....
<select name="end_date_year" id="end_date_year">....
You would optimize the function by creating loops, for example, in the "day" section:
for ($i=1;$i<=31;$i++) {
$txtname=(length($i < 2))?'0'.$i:$i; // = 01, 02, 12, etc.
$list .= "<option value=\"$txtname\">$txtname</option>\n";
}
So when submitted, you have day, month, year for start date and end date. Almost done. You compile a mysql/MSsql-friendly variable:
(perl)
$start = qq¦$data{'start_date_year'}-$data{'start_date_month'}-$data{'start_date_day'}¦;
$end = qq¦$data{'end_date_year'}-$data{'end_date_month'}-$data{'end_date_day'}¦;
(PHP)
$start = "$_POST['start_date_year']-$_POST['start_date_month']-$_POST['start_date_day']";
$end = "$_POST['end_date_year']-$_POST['end_date_month']-$_POST['end_date_day']";
NOTE: Do not directly use input variables without cleansing first! Above for example only.
So now all you need to do is
$query = "select * from table where OrderDate >= '$start' and OrderDate <= '$end' order by OrderDate desc";
OR use between instead.