Display A Message If “Where” Criteria Not Met

6 posts by 2 authors in: Forums > CMS Builder
Last Post: May 12, 2010   (RSS)

By gkornbluth - May 11, 2010

Hi all,

(Sorry I posted this in the wrong forum)

I’ve set up a page to list events in 3 separate groups on the page using separate "list records" calls and "where" statements.

1) Ones that have a sponsored field checked
2) Ones that have starting dates or receptions that occur during the upcoming 7 days.
3) Other upcoming events

The sorting works, however I’m trying to display a specific messages depending on whether there are events that are meet the 7 day 'where" criteria and I can’t get that to work.

Here’s the code I’m using. At the beginning of the group:

<?php
list($e_blast_events_noticeRecords, $e_blast_events_noticeMetaData) = getRecords(array(
'tableName' => 'e_blast_events_notice',
'where' => '(NOW() + INTERVAL 7 DAY) >= event_reception_date AND event_reception_date >= TIMESTAMP(CURDATE(), "00:00:00") OR (NOW() + INTERVAL 7 DAY) >= event_start_date AND event_start_date >= TIMESTAMP(CURDATE(), "00:00:00")',
'orderBy'=> 'neverRemove ASC, event_start_date ASC',
));

?>


And to display the messages:
<?php if($e_blast_events_noticeRecords) echo "These events are opening or have a reception during the next 7 days."; ?>

<?php if(!$e_blast_events_noticeRecords) echo "Sorry, none of our events listings are opening or have a reception during the next 7 days.<br />But there are many events listed below to choose from.";
?>


My guess is that the "where" criteria are being ignored and since there are records, the first message always shows.

Any ideas how to fix this?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Display A Message If “Where” Criteria Not Met

By Jason - May 11, 2010

Hi Jerry,

I think you need to group the AND clauses in your WHERE clause. Try this:

<?php
list($e_blast_events_noticeRecords, $e_blast_events_noticeMetaData) = getRecords(array(
'tableName' => 'e_blast_events_notice',
'where' => '((NOW() + INTERVAL 7 DAY) >= event_reception_date AND event_reception_date >= TIMESTAMP(CURDATE(), "00:00:00")) OR ((NOW() + INTERVAL 7 DAY) >= event_start_date AND event_start_date >= TIMESTAMP(CURDATE(), "00:00:00"))',
'orderBy'=> 'neverRemove ASC, event_start_date ASC',
));

?>


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Display A Message If “Where” Criteria Not Met

By gkornbluth - May 12, 2010

Sorry Jason,

That rendered the same result which you can see at http://www.artistsofpalmbeachcounty.org/events2.php

There are no records which meet the where criteria and the message says that there are matching records.

I've attached the event2.php file

Thanks,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

events2.php 26K

Re: [gkornbluth] Display A Message If �Where� Criteria Not Met

By Jason - May 12, 2010

Hi Jerry,

The code you provided looks good. The so your query must be returning something.

You can take a look at exactly what is in your variable by using this code:

<?php showme($e_blast_events_noticeRecords); ?>

This will display all of the contents of the array. If you need some more help, you can email me your CMS login and FTP information to jason@interactivetools.com.

Please don't post this information to the forum.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [gkornbluth] Display A Message If �Where� Criteria Not Met

By Jason - May 12, 2010

Excellent! Glad that worked out.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/