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

Your name:

Reply:


Posted by Jim Michaels on 01/10/06 01:18

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,
<p><?=htmlspecialchars(stripslashes($_POST['somelongtext']))?></p>
because the database regurgitates backslashes on special chars like ' " and
a few others.

"Bob Stearns" <rstearns1241@charter.net> 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'

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация