Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
displaying tonights performing artist

 

 


rez
User

Jun 11, 2009, 2:35 PM

Post #1 of 18 (7731 views)
Shortcut
displaying tonights performing artist Can't Post

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.


ross
Staff / Moderator


Jun 12, 2009, 9:16 AM

Post #2 of 18 (7724 views)
Shortcut
Re: [rez] displaying tonights performing artist [In reply to] Can't Post

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:


Code
<?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 - Product Specialist
support@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/



rez
User

Mar 6, 2010, 8:28 PM

Post #3 of 18 (7504 views)
Shortcut
Re: [ross] displaying tonights performing artist [In reply to] Can't Post

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)


(This post was edited by rez on Mar 6, 2010, 8:30 PM)


gkornbluth
Veteran

Mar 7, 2010, 5:06 PM

Post #4 of 18 (7410 views)
Shortcut
Re: [rez] displaying tonights performing artist [In reply to] Can't Post

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.


Code
<!– 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.


Code
<?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


Code
<?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:


Code
<?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:


Code
<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.


Code
 '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)


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



So here’s how the complete viewer code looked.


Code
  <!– Start of first list viewer code–> 

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
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:


Code
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:


Code
 (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!
http://www.thecmsbcookbook.com

(This post was edited by gkornbluth on Mar 7, 2010, 5:09 PM)


rez
User

Mar 7, 2010, 6:09 PM

Post #5 of 18 (7396 views)
Shortcut
Re: [gkornbluth] displaying tonights performing artist [In reply to] Can't Post

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. :)


(This post was edited by rez on Mar 7, 2010, 8:08 PM)


gkornbluth
Veteran

Mar 7, 2010, 6:14 PM

Post #6 of 18 (7394 views)
Shortcut
Re: [rez] displaying tonights performing artist [In reply to] Can't Post

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!
http://www.thecmsbcookbook.com


rez
User

Mar 7, 2010, 8:50 PM

Post #7 of 18 (7373 views)
Shortcut
Re: [gkornbluth] displaying tonights performing artist [In reply to] Can't Post

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:


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


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


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


any ideas?


(This post was edited by rez on Mar 7, 2010, 9:25 PM)


Damon
Staff / Moderator


Mar 7, 2010, 11:16 PM

Post #8 of 18 (7348 views)
Shortcut
Re: [rez] displaying tonights performing artist [In reply to] Can't Post

Have you considered using removeDate date field to set an expiry date and time for the event?

"Record won't be displayed on website after this date. This allows users to have content automatically "expire" from website after a certain date and time."

Let me know if that is an option and I can answer any questions.

--------------------------------------------------- 
Cheers
Damon Edis
interactivetools.com

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


rez
User

Mar 8, 2010, 12:00 AM

Post #9 of 18 (7342 views)
Shortcut
Re: [Damon] displaying tonights performing artist [In reply to] Can't Post

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.


(This post was edited by rez on Mar 8, 2010, 12:02 AM)


Dave
Staff / Moderator


Mar 8, 2010, 3:17 PM

Post #10 of 18 (7212 views)
Shortcut
Re: [rez] displaying tonights performing artist [In reply to] Can't Post

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
 


rez
User

Mar 12, 2010, 1:07 AM

Post #11 of 18 (7131 views)
Shortcut
Re: [Dave] displaying tonights performing artist [In reply to] Can't Post

Just what I needed, thanks. :)


rgc
User

Feb 23, 2012, 10:10 AM

Post #12 of 18 (1072 views)
Shortcut
Re: [Dave] displaying tonights performing artist [In reply to] Can't Post

I am currently using this code to display only upcoming events

<?php
// load records
list($eventRecords, $eventMetaData) = getRecords(array(
'tableName' => 'event',
'where' => 'date > NOW()',

));
?>

The code works fine displaying only upcoming events, except the day of the event the event does not display! How can i modify this code to display upcoming events including events the same day ?


Jason
Staff / Moderator


Feb 23, 2012, 11:36 AM

Post #13 of 18 (1063 views)
Shortcut
Re: [rgc] displaying tonights performing artist [In reply to] Can't Post

Hi,

You can change the greater than symbol (>) with greater than or equal to (>=) like this:


Code
<?php 
// load records
list($eventRecords, $eventMetaData) = getRecords(array(
'tableName' => 'event',
'where' => 'date >= NOW()',

));
?>

Hope this helps

---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


rgc
User

Feb 23, 2012, 11:41 AM

Post #14 of 18 (1061 views)
Shortcut
Re: [Jason] displaying tonights performing artist [In reply to] Can't Post

I tried that, but today's event still does not display .... it will only display if i change the event date to tomorrow


Dave
Staff / Moderator


Feb 23, 2012, 1:05 PM

Post #15 of 18 (1047 views)
Shortcut
Re: [rgc] displaying tonights performing artist [In reply to] Can't Post

Hi rgc,

Date math can be a bit tricky, I wrote a post about it here:
http://www.interactivetools.com/forum/gforum.cgi?post=78159#78159

What you want is to get the time of the "end of the day". Try replacing NOW() with this:
TIMESTAMP(CURDATE(), "23:59:59")

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com
 


rgc
User

Feb 23, 2012, 5:02 PM

Post #16 of 18 (1041 views)
Shortcut
Re: [Dave] displaying tonights performing artist [In reply to] Can't Post

Thanks for the code Dave, but that did not work, the event dated today did not display .... I am using the following code which appears to work fine, i will just have to check to see that the event gets automatically removed tomorrow (which will be the day after the event). Here is the code i am using:
<?php
list($eventRecords, $eventMetaData) = getRecords(array(
'tableName' => 'event',
'where' => " date >= TIMESTAMP( DATE(NOW() - INTERVAL 1 HOUR) ) ",
));
?>


Dave
Staff / Moderator


Feb 23, 2012, 5:18 PM

Post #17 of 18 (1040 views)
Shortcut
Re: [rgc] displaying tonights performing artist [In reply to] Can't Post

Ahh, I missed the "upcoming" events part and was thinking of "previous" dates. Yea, it's the time part of the date that is causing the challenge.

Your code will show all events on the current day and forward, except between midnight and 1am, in which case it will show the previous day as well.

That might actually be a useful trick if you expected people would check events after midnight. Or failing that, another way to write it would be like this:

date >= CURDATE()

Good luck!

Dave Edis - Senior Developer
interactivetools.com
 


rgc
User

Feb 24, 2012, 4:33 AM

Post #18 of 18 (1020 views)
Shortcut
Re: [Dave] displaying tonights performing artist [In reply to] Can't Post

Perfect! This is the code i was looking for:
<?php
list($eventRecords, $eventMetaData) = getRecords(array(
'tableName' => 'event',
'where' => " date >= CURDATE() ",
));
?>

Both events of the current day and future events display. Thanks Dave