RE: [PHP] help with query
| From: | Jack Sasportas | Date: | Thu, 07 Jun 2012 20:40:20 +0000 |
| Subject: | RE: [PHP] help with query | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318188@lists.php.net to get a copy of this message | ||
Thanks Jim, worked like a charm.
> -----Original Message-----
> From: Jim Lucas [mailto:lists@cmsws.com]
> Sent: Thursday, June 07, 2012 4:08 PM
> To: Jack
> Cc: PHP
> Subject: Re: [PHP] help with query
>
> On 06/07/2012 09:37 AM, Jack wrote:
> > $query = "select a.startdate, a.articleid, c.name, a.title, a.intro,
> > a.datecreated from articles as a, categories as c where (a.startdate =
> > -1 or a.startdate<= {$now}) and (a.enddate = -1 or a.enddate>= {$now})
> > and a.categoryid = c.categoryid order by a.startdate DESC";
>
> $query = "
> SELECT a.startdate,
> a.articleid,
> c.name,
> a.title,
> a.intro,
> a.datecreated
> FROM articles as a,
> categories as c
> WHERE (
> a.startdate = -1
> OR
> a.startdate <= {$now}
> )
> AND (
> a.enddate = -1
> OR
> a.enddate >= {$now}
> )
> -- This line must stay, it is limiting the combination of the data from
> -- both tables
> AND a.categoryid = c.categoryid
> -- You need to add this line to make it work, but keep the previous line
> AND a.categoryid = 1
>
> ORDER BY a.startdate DESC
> ";
>
> --
> Jim Lucas
>
> http://www.cmsws.com/
> http://www.cmsws.com/examples/
> http://www.bendsource.com/