HELP!!! select statement using variables an BETWEEN

HELP!!! select statement using variables an BETWEEN

am 01.12.2005 02:12:15 von bigsamurai

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!!!!

Re: HELP!!! select statement using variables an BETWEEN

am 01.12.2005 05:17:56 von Robert Stearns

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'

Re: HELP!!! select statement using variables an BETWEEN

am 01.12.2005 20:42:39 von bigsamurai

Thank you sooo much. Works like a champ!!!

Re: HELP!!! select statement using variables an BETWEEN

am 10.01.2006 00:18:59 von Jim Michaels

actually, the concatenation operators are not even needed on dates. see
below where I simplified.
if it were a string variable that might have a quote or other special
characters in it, you would want to do that with this:
'" . mysql_escape_string($_POST['somelongtext']) . "'
and when you wanted to display that text,


because the database regurgitates backslashes on special chars like ' " and
a few others.

"Bob Stearns" wrote in message
news:ORujf.9120$DW6.7458@fe03.lga...
> 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'