displaying tonights performing artist

18 posts by 7 authors in: Forums > CMS Builder
Last Post: February 24, 2012   (RSS)

By rez - June 11, 2009

Hello, I am in the middle of making a performance list of bands. I'm confident the list will come out as planned just like it is staticly on the site now:

June

Thurs, June 4- Mary & David Flood
Friday, June 5- Four Friends
Saturday, June 6- Four Friends
Thursday, June 11- Upstroke
Friday, June 12- Four Friends
Saturday, June 13- Francis Bridge Quartet
Thursday, June 18- Lizzie and Friend
Friday, June 19- Four Friends
Saturday, June 20- Four Friends
Thursday, June 25- Lizzie and friend
Friday, June 26- Francis Bridge Quartet
Saturday, June 27- Francis Bridge Quartet



In my performance schedule editor, i have a drop menu of bands from another table and a date filed. Pretty simple. What will be cool is displaying on the home page, Performing tonight: Thursday, June 11- Upstroke

But i have no idea how to code that. Something like:

If there is a band that matches todays date, echo it here. But if there isn't, don't display anything. (notice there aren't performances every night.) So how do you check todays date and see if there is an entry in my databse and display it? Probably pretty simple :) but i didnt find anything here.

Re: [rez] displaying tonights performing artist

By ross - June 12, 2009

Hi there.

Thanks for posting!

There are probably several ways to do this but the first one I thought of was to use an IF statement. Try something like this:

<?php if (date("D, M jS", strtotime($record['date'])) == date("D, M jS")): ?>
ALL YOUR CODE GOES HERE
<?php endif ?>


That should get you going. The only thing is $record['date'] might be different for you. That's the name of the field for date.

Give this a shot and let me know what you think :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] displaying tonights performing artist

By rez - March 6, 2010 - edited: March 6, 2010

Hello,

any way of displaying tonights artist plus the next 4 upcoming artists or more?

The idea is that i want to show the next 4 or so but not one that the date has already passed (without having to delete entries or manually move things)

Re: [rez] displaying tonights performing artist

By gkornbluth - March 7, 2010 - edited: March 7, 2010

Hi Rez,

As Dave Edis says, "Date math makes my head hurt." Well, it hurts mine too.

That said, here are 2 (long) recipes that might be modified to reach your goal. They're taken out of my CMSB Cookbook http://www.thecmsbcookbook.com

Good Luck,

Jerry Kornbluth

COMPARING DATES
When combined with the “if” statement, this extremely useful concept can be used to show or hide fields based on a particular date, automatically archive records after a specified time period and perform many other functions.

Here’s the basic idea of how to compare a date field to today’s date on a list page. This example uses a date field called “opening_reception” in a multi record editor called “exhibitions”. The goal was to automatically hide the opening reception date after the date had passed.

<!– First you’ll need a “foreach” statement to display each record. -->

<?php foreach ($exhibitionsRecords as $record): ?>


Since dates are normally expressed as months, days and years are hard to compare mathematically, the dates are converted to the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

Note that dates are referenced to local time as set in the CMSB “General Settings” information and not server time.

Dave suggested to first define a few variables and to use simple, descriptive names so that the process is easier to follow. Then set some rules for the comparisons. You can use mathematical operators like <, >, <= or >= between values to compare them in different ways.

<?php
$eventUnixTime = strtotime( $record['reception_date'] ); // seconds since 1970
$eventDateString = date("l, F jS", $eventUnixTime); // example format: Monday, June 1st
$currentUnixTime = time();
$currentDateString = date("l, F jS", $currentUnixTime);


$isEventToday = ($eventDateString == $currentDateString); // first comparison
$isEventOver = !$isEventToday && ($eventUnixTime < $currentUnixTime); // second comparison
$isFutureEvent = !$isEventOver && !$isEventToday; // third comparison
?>


Then it becomes a simple matter of comparing the variables

<?php if ($isFutureEvent): ?>
Opening Reception: <?php echo $eventDateString ?>

<?php elseif ($isEventToday): ?>
The Opening reception is today. Don't miss it!!

<?php else: ?>
Sorry, you missed the Opening Reception.

<?php endif; ?>

<!– and don’t forget the endforeach statement to close your loop.–>

<?php endforeach ?>



Or, Let’s say you want to group a set of meetings by current, future and past dates

You could use:

<?php foreach ($general_meetingsRecords as $record): ?>
<?php
$eventUnixTime = strtotime( $record['date'] ); // seconds since 1970
$eventDateString = date("l, F jS", $eventUnixTime); // example format: Monday, June 1st
$currentUnixTime = time();
$currentDateString = date("l, F jS", $currentUnixTime);

$isEventToday = ($eventDateString == $currentDateString);
$isEventOver = !$isEventToday && ($eventUnixTime < $currentUnixTime);
$isFutureEvent = !$isEventOver && !$isEventToday;
?>

<?php if ($isEventToday): ?> <p>

<div align="center"class="heading-text-bold">TONIGHT'S MEETING:</div>
</p>
<br /> <span class="body-text-bold"><?php echo date("D, M jS, Y g:i a", strtotime($record['date'])) ?>
</span>
<br />
<div align="left" class="body-text"><?php echo $record['content'] ?></div>
<hr align="left" color="#A29DB2" width="100" /><br />
<?php endif; ?> <?php endforeach ?>
</div>
<p>

<div align="center"class="heading-text-bold">UPCOMING MEETINGS:</div>
</p>
<?php foreach ($general_meetingsRecords as $record): ?>

<?php
$eventUnixTime = strtotime( $record['date'] ); // seconds since 1970
$eventDateString = date("l, F jS", $eventUnixTime); // example format: Monday, June 1st
currentUnixTime = time();
$currentDateString = date("l, F jS", $currentUnixTime);

$isEventToday = ($eventDateString == $currentDateString);
$isEventOver = !$isEventToday && ($eventUnixTime < $currentUnixTime);
$isFutureEvent = !$isEventOver && !$isEventToday;
?>

<?php if ($isFutureEvent): ?>
<br />
<span class="body-text-bold"><?php echo date("D, M jS, Y g:i a", strtotime($record['date'])) ?></span> <br />

<div align="left" class="body-text"> <?php echo $record['content'] ?></div><hr align="left" color="#A29DB2" width="100" />
<?php endif; ?> <?php endforeach ?>
<br />
<p><div align="center" class="heading-text-bold">PAST MEETINGS:</div></p>

<?php foreach ($general_meetingsRecords as $record): ?>

<?php
$eventUnixTime = strtotime( $record['date'] ); // seconds since 1970
$eventDateString = date("l, F jS", $eventUnixTime); // example format: Monday, June 1st
$currentUnixTime = time();
$currentDateString = date("l, F jS", $currentUnixTime);

$isEventToday = ($eventDateString == $currentDateString);
$isEventOver = !$isEventToday && ($eventUnixTime < $currentUnixTime);
$isFutureEvent = !$isEventOver && !$isEventToday;
?>

<?php if ($isEventOver): ?>
<br />
<span class="body-text-bold"><?php echo date("D, M jS, Y g:i a", strtotime($record['date'])) ?></span> <br />


<div align="left" class="body-text"><?php echo $record['content'] ?></div><hr align="left" color="#A29DB2" width="100" />
<?php endif; ?> <?php endforeach ?>
</div>


Note that you have to redefine the variables for each "foreach" loop

If you want to compare other field values, just define more variables and compare those as well.

If you want to test for the values of the variable that you're using. Try something like this in your “foreach” loop:

<ul>
<li>Event date = <?php echo $eventDateString ?></li>
<li>Current date = <?php echo $currentDateString ?></li>
<li>$isEventToday = <?php echo $isEventToday ? "true" : "false" ?></li>
<li>$isEventOver = <?php echo $isEventOver ? "true" : "false" ?></li>
<li>$isFutureEvent = <?php echo $isFutureEvent ? "true" : "false" ?></li>
<li>$CurrentUnixTime extended = <?php echo date("l jS \of F Y h:i:s A", $currentUnixTime); ?></li>

</ul>


AND THE SECOND ONE

LISTING RECORDS WITHIN A DATE RANGE
My client wanted to list all of the events on their list page, but wanted to make a special list at the top of the page for those events with receptions that were going to occur within the upcoming week.

Thanks to Dave Edis of Interactive Tools (again) who freely admits that date math makes his head hurt, we came up with the following.

First I created a date field in my ‘date_compare_test’ multi record editor called ‘reception_date’.

Then came the task of creating a list viewer that would list only the events I wanted in the appropriate groups.

Dave came up with the idea of putting 2 viewers on my list viewer page and using 2 different ‘where’ statements in the get records calls to separate the content that could show in each area.

Here's the 'where' statement that we used to show reception_ dates for the upcoming week, as you suggested.

'where' => '(NOW() + INTERVAL 7 DAY) >= reception_date AND reception_date >= TIMESTAMP(CURDATE(), "00:00:00")',

And here's the 'where' statement that we used to show all the other events (and leave out those already listed)

'where' => 'reception_date <= TIMESTAMP(NOW()) OR reception_date >= TIMESTAMP(NOW()+ INTERVAL 7 DAY)',

So here’s how the complete viewer code looked.

<!– Start of first list viewer code–>

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

require_once "/hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/cmsAdmin/lib/viewer_functions.php";

list($date_compare_testRecords, $date_compare_testMetaData) = getRecords(array(
'tableName' => 'date_compare_test',
'where' => '(NOW() + INTERVAL 7 DAY) >= reception_date AND reception_date >= TIMESTAMP(CURDATE(), "00:00:00")',
));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />



<hr />


EVENTS WITH RECEPTIONS TODAY THROUGH 7 DAYS IN THE FUTURE<br /><br />
<?php foreach ($date_compare_testRecords as $record): ?>
Title: <?php echo $record['title'] ?><br/>
The Reception Date is <?php echo date("D, M jS, Y g:i a", strtotime($record['reception_date'])) ?> <br />
<?php endforeach ?>
<hr />

</body>
</html>

<!– Start of second list viewer code–>

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

require_once "/hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/cmsAdmin/lib/viewer_functions.php";

list($date_compare_testRecords, $date_compare_testMetaData) = getRecords(array(
'tableName' => 'date_compare_test',
'where' => 'reception_date <= TIMESTAMP(NOW()) OR reception_date >= TIMESTAMP(NOW()+ INTERVAL 7 DAY)',



));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
EVENTS WITH RECEPTIONS BEFORE TODAY OR MORE THAN 7 DAYS IN THE FUTURE<br /><br />
<?php foreach ($date_compare_testRecords as $record): ?>

Title: <?php echo $record['title'] ?><br/>
The Reception Date is <?php echo date("D, M jS, Y g:i a", strtotime($record['reception_date'])) ?> <br />
<?php endforeach ?>

</body>
</html>


Dave explained that for date queries,

“The first step is to figure out if you need to do it in MySQL or PHP. If you are able to do it in MySQL it's often simpler.

You can find a list of MySQL date/time functions here:

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

And here are some examples:

NOW() - Gives you the current date and time: 2010-03-01 09:41:50
(NOW() + INTERVAL 7 DAY) - Get date/time 7 days from now: 2010-02-22 09:45:25
CURDATE() - Gives you the current date only: 2010-03-01
TIMESTAMP() - Format value as date/time, or if two values, add them together
TIMESTAMP(CURDATE()) - Get date/time at beginning of day: 2010-03-01 00:00:00
TIMESTAMP(CURDATE(), “23:59:59") - Get date/time at end of day 2010-03-01 23:59:59


You can test all these with the MySQL Console Plugin by entering SELECT followed by the function. So: SELECT NOW() in the Mysql Console returns: 2010-03-01 09:41:50

So the first step is to figure out the values you want to compare. My guess is you want:
The date 7 days from now: (NOW() + INTERVAL 7 DAY)
The reception date: reception_date
The date at the end of today: TIMESTAMP(CURDATE(), “23:59:59")

If you write it out in English first it's way easier:
- If the reception_date is 7 days or less from now
- AND the reception_date hasn't already passed

I like to arrange my code so if reads like a time range with the test date in the middle like this:
start_date >= test_date AND test_date >= end_date

So that would be:

(NOW() + INTERVAL 7 DAY) >= reception_date AND reception_date >= TIMESTAMP(CURDATE(), “00:00:00")


Now I understand why date math makes Dave’s head hurt.
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] displaying tonights performing artist

By rez - March 7, 2010 - edited: March 7, 2010

Thanks for that. I did find this since my question:

http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=76332;search_string=show%20today;t=search_engine#76332

but you have cleared things up and have given me a lot of ideas. I guess I didnt need this when browsing through your cookbook and didnt remember that section.

Fun stuff. Thanks. :)

Re: [rez] displaying tonights performing artist

By gkornbluth - March 7, 2010

Thanks, and I'll look at the other post and include the idea in the Cookbook as well.

Best,

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

Re: [gkornbluth] displaying tonights performing artist

By rez - March 7, 2010 - edited: March 8, 2010

I think you pretty much covered the other thread already. :)

I'm struggling with showing todays event until 2am which is when pubs close here. If someone checks the site at 12:30am, I need "todays" (I should call it "tonights")show to display until 2am.

this is wrong and missing the range but trying MySQL things like:

'where' => 'TIMESTAMP(CURDATE() - INTERVAL 1 DAY, "02:00:00")'

Then I want to list somewhere tonights show (until 2am + the next 31 days:

'where' => '(NOW() + INTERVAL 31 DAY) >= event_date AND event_date >= DATE_SUB(CURDATE(), -2 HOUR)',

any ideas?

Re: [Damon] displaying tonights performing artist

By rez - March 8, 2010 - edited: March 8, 2010

I think it would be nicer if the user didnt have to specify 2 dates plus a time to remove.

Unless the user doesnt have to worry about the time to remove the show with removeDate. ? If the removeDate was show date 23:59:59 + 2 hours which would automatically remove tonights show after 2am. ?

I have no idea how to do that with removeDate but imagine it would be in the body of the page? I may have over complicated things and I'm pretty confused at this point. Currently, all my show dates are being removed at midnight and i dont know what to try next.

Re: [rez] displaying tonights performing artist

By Dave - March 8, 2010

Hi Rez,

That's a tricky one. How about this:
TIMESTAMP( DATE(NOW() - INTERVAL 2 HOUR) )

It gets the date for the time as of 2 hours ago, such as: 2010-03-08 00:00:00. So from midnight to 2 am it returns yesterdays date, and from 2am to midnight it returns todays date.

So you'd have:
'where' => " event_date >= TIMESTAMP( DATE(NOW() - INTERVAL 2 HOUR) ) ",

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com