|
Posted by Bob Stearns on 09/30/76 11:33
bigsamurai wrote:
> I have the following statement...
>
> $query = "SELECT ood.ood_watch_officer, ood.ood_start, ood.ood_end,
> ood.ood_date, ood.ood_usvn_pop, ood.ood_sen_off_pop, ood.ood_summary,
> ood_per.ood_per_no, ood_per.ood_per_name FROM ood, ood_per WHERE
> ood.ood_watch_officer=ood_per.ood_per_no AND (ood_date BETWEEN
> "$_POST[date1]" AND "$_POST[date2]") ORDER by ood_per.ood_per_name";
>
> The date1 and date 2 variable come in the form of yyyy-mm-dd. i al
> looking to get information between two dates.
>
> ANyhelp would be GREAT!!!!
>
$query = "SELECT ood.ood_watch_officer,
ood.ood_start, ood.ood_end,
ood.ood_date, ood.ood_usvn_pop,
ood.ood_sen_off_pop, ood.ood_summary,
ood_per.ood_per_no,
ood_per.ood_per_name
FROM ood, ood_per
WHERE ood.ood_watch_officer=ood_per.ood_per_no
AND (ood_date BETWEEN '" . $_POST["date1"] . "'"
. " AND '" . $_POST["date2"] . "')" .
" ORDER by ood_per.ood_per_name";
or easier to read
$d1 = $_REQUEST["date1"];
$d2 = $_REQUEST["date2"];
$query = "SELECT ood.ood_watch_officer,
ood.ood_start, ood.ood_end,
ood.ood_date, ood.ood_usvn_pop,
ood.ood_sen_off_pop, ood.ood_summary,
ood_per.ood_per_no,
ood_per.ood_per_name
FROM ood, ood_per
WHERE ood.ood_watch_officer=ood_per.ood_per_no
AND ood_date BETWEEN '$d1' AND '$d2'
ORDER by ood_per.ood_per_name
";
Note the use of apostrophes in the query and quotes arount the
subscripts of the super globals.
While this is legal syntax, the intent would be clearer, in my opinion,
with the following:
FROM ood
JOIN ood_per ON ood.ood_watch_officer=ood_per.ood_per_no
WHERE ood_date BETWEEN '$d1' AND '$d2'
Navigation:
[Reply to this message]
|