filter listings by two categories + today's date forward

4 posts by 3 authors in: Forums > CMS Builder
Last Post: March 31, 2010   (RSS)

By Deborah - March 30, 2010

I'd like to show calendar listings from two categories, but only those listings that are for today or the next 365 days in the future.

I can show ALL listings from two categories such as:
'where' => " category LIKE '%\tMusic - Events\t%' or category LIKE '%\tArt - Events\t%' ",

And when I haveone category and add the date requirement, it works with this:
'where' => ' category LIKE "%\tFriends - Events\t%" AND (NOW() + INTERVAL 365 DAY) >= date AND date >= TIMESTAMP(CURDATE(), "00:00:00") ',

But, when combining the two, I end up with NO listings displayed, using the following code:
'where' => ' category LIKE "%\tMusic - Events\t%" OR category LIKE "%\tArt - Events\t%" AND (NOW() + INTERVAL 365 DAY) >= date AND date >= TIMESTAMP(CURDATE(), "00:00:00") ',

I'm hoping this is an obvious syntax error for someone here and would be very grateful for any advice.

Deborah

Re: [chris] filter listings by two categories + today's date forward

By Deborah - March 30, 2010

Chris,

Your correction seems to be just what was needed. Thank you so much! I shall document example that for future projects.

Deborah

Re: [Deborah] filter listings by two categories + today's date forward

By Dave - March 31, 2010

A tip for anyone with similar issues: MySQL ignores extra whitespace, so I often add extra spaces and line breaks to make it easier for me to read the code at a glance. Example:

'where' => '(category LIKE "%\tMusic - Events\t%" OR category LIKE "%\tArt - Events\t%")
AND (NOW() + INTERVAL 365 DAY) >= date
AND date >= TIMESTAMP(CURDATE(), "00:00:00") ',


And I often add extra parenthesis as well, as I've been bitten by this more than a few times myself! :)
Dave Edis - Senior Developer
interactivetools.com