Click to See Complete Forum and Search --> : Event Calendar
kproc
02-27-2007, 07:23 PM
Hi
I'm looking for a tutorial or some script to get me started in creating an event calendar. I have done some search and found some great calendars but nothing that I can get to do what i want
What I want to do
Input
Users can enter events into a mysql database
Output
Events displayed on the calendar on the date in which they occur with the option to click a link to display the complete details
Thanks for any help
aj_nsc
02-27-2007, 07:32 PM
http://www.phpfreaks.com/tutorials/83/0.php
Best thing you can get. I added a function to this code to pull events out of a mysql database. I can't remember if there are bugs in this code or not, but I know I modified mine because it wasn't working right, but maybe I messed it up myself before I 'fixed' it :D. If you need any assistance, let me know, I've got this one working perfectly for me.
kproc
02-27-2007, 07:34 PM
I came accross that one but it does not add the events to the specific dates.
aj_nsc
02-27-2007, 07:37 PM
It can, quite easily. You just have to modify the code a little. If you know enough about mysql to put specific events into a database, you should learn enough about php to pull them out. I'd be more than happy to show you the function I wrote if you want.
kproc
02-27-2007, 08:07 PM
that would be greatly appreciated, I just got the calendar to display, know to show the event titles in the correct dates:confused:
aj_nsc
02-27-2007, 09:04 PM
I was going to type in how to do this, but instead I think I'll post my entire calendar script. I'll just post a couple of comments in it to show you were to look and what I did.
As I have in my comments, don't get caught up in the specifics of the exact code I used, just use it to see how you can pull events from a database and get them to display on a specific day for your calendar. Hope this helps.
kproc
02-27-2007, 09:59 PM
Thank you for all your help, I'm having hard time piecing this one together and following your code, It looks nothing like the tutorial from PHP freaks.
NightShift58
02-27-2007, 10:05 PM
//CREATE AN OFFSET TO CALCULATE WHICH COLUMN (Sun-Sat) THE FIRST DAY GOES IN
switch($month_start_day) {
case "Sun"; $offset = 0; break;
case "Mon"; $offset = 1; break;
case "Tue"; $offset = 3; break;
case "Wed"; $offset = 4; break;
case "Thu"; $offset = 5; break;
case "Fri"; $offset = 6; break;
case "Sat"; $offset = 7; break;
}Is this correct?
kproc
02-27-2007, 10:09 PM
This code is from phpfreaks. I did some editing.
what it does this far,
displays the calendar and when there is an event on a given date the date value shows has a hyperlink,
what is does not do
when I click the link nothing happens
What I want it to do
Display the event time under the date value.
I'm having a hard time thinking through this one.
<?
include ("../Connections/db.php");
// Database connection variables
function getEventDays($month, $year) {
$days = array();
$sql = mysql_query("SELECT DAY(event_date) AS day, COUNT(event_id) FROM calendar_events WHERE MONTH(event_date) = '$month' AND YEAR(event_date) = '$year' GROUP BY day");
if (mysql_num_rows($sql) > 0) {
while ($row = mysql_fetch_array($sql)) $days[] = $row['day'];
}
return $days;
}
function drawCalendar($month, $year) {
// set variables we will need to help with layouts
$first = mktime(0,0,0,$month,1,$year); // timestamp for first of the month
$offset = date('w', $first); // what day of the week we start counting on
$daysInMonth = date('t', $first);
$monthName = date('F', $first);
$weekDays = array('Su', 'M', 'Tu', 'W', 'Th', 'F', 'Sa');
$eventDays = getEventDays($month, $year);
$i = 0;
for ($d = (1 - $offset); $d <= $daysInMonth; $d++) {
if ($i % 7 == 0) $out .= "<tr>\n"; // Start new row
if ($d < 1) $out .= "<td class=\"nonMonthDay\"> </td>\n";
else {
if (in_array($d, $eventDays)) {
$out .= "<td class=\"monthDay\">\n";
$out .= "<a href=\"?year=$year&month=$month&day=$d\">$d</a>\n";
$out .= "</td>\n";
} else $out .= "<td class=\"monthDay\">$d</td>\n";
}
++$i; // Increment position counter
if ($i % 7 == 0) $out .= "</tr>\n"; // End row on the 7th day
}
// Round out last row if we don't have a full week
if ($i % 7 != 0) {
for ($j = 0; $j < (7 - ($i % 7)); $j++) {
$out .= "<td class=\"nonMonthDay\"> </td>\n";
}
$out .= "</tr>\n";
}
// Calendar is done, let's list events for selected day
$sql = mysql_query("SELECT * FROM calendar_events WHERE event_date = '$year-$month-$day'");
if (mysql_num_rows($sql) > 0) {
while ($e = mysql_fetch_array($sql)) {
echo "<p>$e[event_title]</p>\n";
}
} else {
echo "<p>No events today</p>\n";
}
?>
NightShift58
02-27-2007, 10:26 PM
$out .= "<a href=\"?year=$year&month=$month&day=$d\">$d</a>\n";How about adding the page name and not just the URL parameters?
kproc
02-27-2007, 10:41 PM
doh? should have looked harder. any thoughts how to get the events to display with there corresponding dates
kproc
02-27-2007, 10:52 PM
Below is what I have this far. The function is not working. not sure why
<?
include ("../Connections/db.php");
// Database connection variables
function getEventDays($month, $year) {
$days = array();
$sql = mysql_query("SELECT DAY(event_date) AS day, COUNT(event_id) FROM calendar_events WHERE MONTH(event_date) = '$month' AND YEAR(event_date) = '$year' GROUP BY day");
if (mysql_num_rows($sql) > 0) {
while ($row = mysql_fetch_array($sql)) $days[] = $row['day'];
}
return $days;
}
function entryInfoQuery($date,$month,$monthname,$year) {
$query_result = mysql_query("SELECT * FROM calendar_events WHERE DAY(event_date)='$date' AND MONTH(event_date)='$month' AND YEAR(event_date)='$year'");
$num = mysql_numrows($query_result);
if ($num > 1) {
$i=0;
while ($i < $num) {
$event = mysql_result($query_result,$i,"event_title");
$time = mysql_result($query_result,$i,"event_time");
$body[$i] = "$event @ $time";
$i++;
}
$body_var = join("<br />",$body);
$title = "title=\"header=[$date $monthname $year] body=[$body_var]\"";
unset ($event_array); //CLEAR THE ARRAY FOR THE NEXT TIME THE FUNCTION IS CALLED
return $title;
}
else {
return "";
}
}
function drawCalendar($month, $year) {
// set variables we will need to help with layouts
$first = mktime(0,0,0,$month,1,$year); // timestamp for first of the month
$offset = date('w', $first); // what day of the week we start counting on
$daysInMonth = date('t', $first);
$monthName = date('F', $first);
$weekDays = array('Su', 'M', 'Tu', 'W', 'Th', 'F', 'Sa');
$eventDays = getEventDays($month, $year);
$i = 0;
for ($d = (1 - $offset); $d <= $daysInMonth; $d++) {
if ($i % 7 == 0) $out .= "<tr>\n"; // Start new row
if ($d < 1) $out .= "<td class=\"nonMonthDay\"> </td>\n";
else {
if (in_array($d, $eventDays)) {
$title = "";entryInfoQuery($d,($month-1),$prevMonth_name,$prevMonthYear);
$out .= "<td class=\"monthDay\">\n";
$out .= "<a href=\"?year=$year&month=$month&day=$d\">$d</a>\n<br />";
$out .= "$title";
$out .= "</td>\n";
} else $out .= "<td class=\"monthDay\">$d</td>\n";
}
++$i; // Increment position counter
if ($i % 7 == 0) $out .= "</tr>\n"; // End row on the 7th day
}
// Round out last row if we don't have a full week
if ($i % 7 != 0) {
for ($j = 0; $j < (7 - ($i % 7)); $j++) {
$out .= "<td class=\"nonMonthDay\"> </td>\n";
}
$out .= "</tr>\n";
}
$sql = "SELECT event_date FROM calendar_events GROUP BY event_date ORDER BY event_date";
$qry = mysql_query($sql) or die("SQL Error: $sql<br" . mysql_error());