Date/Calendar-events set-up

8 posts by 2 authors in: Forums > CMS Builder
Last Post: April 21, 2010   (RSS)

By design9 - April 13, 2010

I was wondering if someone could guide me in the right direction:

1) I want to know the best way to set up a list page so it only shows events for the current day. Each day I want it to automatically change/update with the events for that day (most current date).

2) I also have start date and end date fields in my backend and was wondering what is the easiest set up to add a search to my page using those fields so the user can search a dropdown list from a specific start date to the end date. Ex: If they wanted to search all events from April 15 to April 16, they would pull down the April 15 date from the start date dropdown and then the April 16 date from the end date dropdown. Here is an example of that type of search on the following website: http://www.dallaschild.com/showcalendar.asp

Thanks!

April

Re: [apdance9] Date/Calendar-events set-up

By Jason - April 13, 2010

Hi April,

So, you want a display page that will display the events that have a start date that is between the 2 dates that the user enters. If they don't enter 2 dates, you want to display all the events whose start date is the current day. Is that right?

If so, you can try this. Put this code near the top of your display page.

<?php
$today="'".date('Y-m-d',time())."'"; //Today's date

if(@$_REQUEST['start_date']){ //if the user has submitted a search
//Get Start and End date
$start_date="'".mysql_escape(@$_REQUEST['start_date'])."'";
$end_date="'".mysql_escape(@$_REQUEST['end_date'])."'";

list($eventRecord,$eventMetaData)=getRecords(array(
'tableName' => 'events',
'where' => 'start_date between '.$start_date." AND ".$end_date,
'allowSearch'=>0,

));

}
else{//No search. Only dispaly events with a a start date of today.
list($eventRecord,$eventMetaData)=getRecords(array(
'tableName' => 'events',
'where' => 'start_date='.$today,

));
}

?>


So, at the end of this code, $eventRecord will have either a list of records whose start date is between the 2 search dates, or a list of events for that day. You'll have to change the names so they match the names in your database.

Hope this helps. Let me know if you need anymore help.
---------------------------------------------------
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] Date/Calendar-events set-up

By design9 - April 13, 2010

Hi Jason,
Yes, for the search area, I would want the search to go between the start and end date like you stated. Would I need any adjustments in the code below?

However, what I was talking about for the current date...I am going to have the main list page where I want to show events for the current day. So, when you first go to the calendar page, it will automatically show events for that day. Example: let's use today's date, April 13, 2010, when we go to the main page, it will show a list of all the events for April 13, Then if I were to go to the page tomorrow on April 14, 2010, it will have changed to show events for April 14. The main page would show events for the current date. Then on that main page, I want to have the search options, so users can select a range of dates or specific date, search by keyword, search by a category, etc. which is what I need the code above for.

I am using this page as an example, http://www.dallaschild.com/showcalendar.asp
I would have the search options at the top of the page and where they have "in the spotlight" I would actually use that space to list all the events for the current date.

Hopefully this makes sense.
Thanks!
April

Re: [apdance9] Date/Calendar-events set-up

By Jason - April 14, 2010

Hi April.

Okay, I see. The code I posted will pretty much stay the same. On your main page where you want to display only events for that day, you would use this code:
<?php
$today="'".date('Y-m-d',time())."'"; //Today's date
list($eventRecord,$eventMetaData)=getRecords(array(
'tableName' => 'events',
'where' => 'start_date='.$today,

));
?>


The events for that day will be stored in $eventRecord. The variable $today will change with each day.

For the search page where you would be search between 2 dates, you can use this code:

<?php
//Get Start and End date
$start_date="'".mysql_escape(@$_REQUEST['start_date'])."'";
$end_date="'".mysql_escape(@$_REQUEST['end_date'])."'";

list($eventRecord,$eventMetaData)=getRecords(array(
'tableName' => 'events',
'where' => 'start_date between '.$start_date." AND ".$end_date,
'allowSearch'=>0,
));
?>


Again, events that all between those 2 dates will be stored in $eventRecord.

You'll only need to change some of the names in this code so it matches the names in your database and the search form.

I hope this helps.

Let me know if you need any more help.
---------------------------------------------------
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] Date/Calendar-events set-up

By design9 - April 19, 2010

Jason,
The coding is great. Have one other question. I hate to be so ignorant but I am having trouble figuring out what type of search I will need to use to make the search between a start date and a end date work. I am using a date picker script, you can see the basic script here: http://www.charlotteparent.com/test/thingstodo/calendar/test.html
but cannot figure out what type of search I need to include with it to make it search the dates and then go to the search page where I have the coding you gave me:
<?php
//Get Start and End date
$start_date="'".mysql_escape(@$_REQUEST['start_date'])."'";
$end_date="'".mysql_escape(@$_REQUEST['end_date'])."'";

list($eventRecord,$eventMetaData)=getRecords(array(
'tableName' => 'events',
'where' => 'start_date between '.$start_date." AND ".$end_date,
'allowSearch'=>0,
));
?>
I have placed that on a search page: http://www.charlotteparent.com/test/thingstodo/calendar/datesearch.php

Thanks for your help!
April

Re: [apdance9] Date/Calendar-events set-up

By Jason - April 20, 2010

Hi April,

This is what we can do to get the date search up and running. First, we need to change our page where the user selects the date. Use this code:
<div align="center"><p><br /><br />
<form action="datesearch.php" method="post">
Start Date: <input name="start_date" id="demo1" type="text" size="25"><a href="javascript:NewCal('demo1','mmddyyyy')"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a><p>
End Date: <input name="end_date" id="demo2" type="text" size="25"><a href="javascript:NewCal('demo2','mmddyyyy')"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
<br />
<input type="submit" value="Search" /></form>
</div><p><p>


The form tag tells the browser to send the user information to "datesearch.php" it also gives the names "start_date" and "end_date" to our text boxes.

Next, on datasearch.php we can use this code:
<?php

if(@$_REQUEST['start_date'] && @$_REQUEST['end_date']){
//Get Start and End date
$start=str_replace("-","/",$_REQUEST['start_date']);
$end=str_replace("-","/",$_REQUEST['end_date']);

$start_date=date( 'Y-m-d H:i:s', strtotime($start) );
$end_date=date( 'Y-m-d H:i:s', strtotime($end) );

list($eventRecord,$eventMetaData)=getRecords(array(
'tableName' => 'events',
'where' => 'start_date between '."'".mysql_escape($start_date)."' AND '".mysql_escape($end_date)."'",
'allowSearch'=>0,

));


}

?>


This will only execute if the user has selected both a start and end date. It will change the dates to a format that MySQL will recognize and then execute the search. At the end, $eventRecord will contain a list of all events whose start_date falls between the entries the user made.

You may have to change the code a little to match the names you use in the database.
Give that a try and let me know if it works 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/

Re: [apdance9] Date/Calendar-events set-up

By Jason - April 21, 2010

Hi April,

You can print the current date in the format you're using like this:
<?php echo date('l, F j, Y',time()) ?>

If you want all of the text to be uppercase, use this:
<?php echo strtoupper(date('l, F j, Y',time())) ?>

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/