Trying to convince myself (and Exec. Dir) that we can use php to pull calendar event data from a MySQL database and display the results on our web site (i.e., "we have these events coming up, these are the dates, times, locations, description of activities, etc etc). I could always put this into static HTML tables, but I'd rather it be dynamic.
I'm just learning php and was hoping to find a php "event calendar" that already does what I'm trying to accomplish.
Can anyone help?
TIA
Event Calendar using PHP/MySQL
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
skyhawk133
- Forum Newbie
- Posts: 9
- Joined: Wed Nov 13, 2002 10:25 pm
- Location: Rio Rancho, NM
Try this, fiddle with the mySQL code as you fit. but the calendar code should work fine. comment out the mySQL parts to see just the calendar.
Code: Select all
<? // If the $Month and $Year values don't exist, make them the current month and year.
if ((!$Month) && (!$Year)) {
$Month = date ("m");
$Year = date ("Y");
}
// Calculate the viewed Month.
$Timestamp = mktime(0, 0, 0, $Month, 1, $Year);
$MonthName = date("F", $Timestamp);
// Make a table with the proper month.
?>
<table border=0 cellpadding=0 cellspacing=0 width=90% align=center bgcolor=black>
<tr>
<td>
<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 WIDTH=100% HEIGHT=400 ALIGN=CENTER>
<TR bgcolor="<? echo $nav_bgcolor?>">
<TD COLSPAN=7 HEIGHT=50 ALIGN=CENTER>
<FONT COLOR=BLACK><B><? echo "$MonthName $Year"; ?> </B> </FONT>
</TD>
</TR>
<TR BGCOLOR=#CCCCCC HEIGHT="15">
<TD ALIGN=CENTER WIDTH=14%>
<FONT COLOR=BLACK SIZE=1><B>Sunday</B></FONT>
</TD>
<TD ALIGN=CENTER WIDTH=14%>
<FONT COLOR=BLACK SIZE=1><B>Monday</B></FONT>
</TD>
<TD ALIGN=CENTER WIDTH=14%>
<FONT COLOR=BLACK SIZE=1><B>Tuesday</B></FONT>
</TD>
<TD ALIGN=CENTER WIDTH=14%>
<FONT COLOR=BLACK SIZE=1><B>Wednesday</B></FONT>
</TD>
<TD ALIGN=CENTER WIDTH=14%>
<FONT COLOR=BLACK SIZE=1><B>Thursday</B></FONT>
</TD>
<TD ALIGN=CENTER WIDTH=14%>
<FONT COLOR=BLACK SIZE=1><B>Friday</B></FONT>
</TD>
<TD ALIGN=CENTER WIDTH=14%>
<FONT COLOR=BLACK SIZE=1><B>Saturday</B></FONT>
</TD>
</TR>
<?
$MonthStart = date("w", $Timestamp);
if ($MonthStart == 0) {
$MonthStart = 7;
}
$LastDay = date("d", mktime (0, 0, 0, $Month + 1, 0, $Year));
$StartDate = -$MonthStart;
for ($k = 1; $k <= 6; $k++) { // Print 6 rows.
echo "<TR BGCOLOR=WHITE>";
for($i = 1; $i <= 7; $i++) { // Use 7 columns.
$StartDate++;
if(($StartDate <= 0) || ($StartDate > $LastDay)) {
echo "<TD BGCOLOR=#EEEEEE width=14% height=60> &nbsp; </TD>";
} elseif (($StartDate >=1) && ($StartDate <= $LastDay)) {
$sql = "SELECT date FROM calendar WHERE date = '$Year-$Month-$StartDate' ";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
// format results by row
$num_events = mysql_num_rows($sql_result);
$event = "Events";
if ($num_events != 0) {
if ($num_events == 1) {
$event = "Event";
}
echo "<TD ALIGN=LEFT VALIGN=TOP width=14% height=60><a href='calendar.php?a=details&m=$Month&d=$StartDate&y=$Year'><b><font size=2>$StartDate</font></b></a><br><font size=1><br>$num_events $event</font></TD>";
}
else
{
echo "<TD ALIGN=LEFT VALIGN=TOP width=14% height=60><a href='calendar.php?a=details&m=$Month&d=$StartDate&y=$Year'><font size=2>$StartDate</font></TD>";
}
}
}
echo "</TR>";
}
?>
</TABLE>
</td>
</tr>
</table>
<?
// Make the form.
echo "<FORM ACTION=$PHP_SELF METHOD=GET>
<CENTER>
Select a new month to view <BR>
<SELECT NAME=Month>
<OPTION VALUE=1>January</OPTION>
<OPTION VALUE=2>February</OPTION>
<OPTION VALUE=3>March</OPTION>
<OPTION VALUE=4>April</OPTION>
<OPTION VALUE=5>May</OPTION>
<OPTION VALUE=6>June</OPTION>
<OPTION VALUE=7>July</OPTION>
<OPTION VALUE=8>August</OPTION>
<OPTION VALUE=9>September</OPTION>
<OPTION VALUE=10>October</OPTION>
<OPTION VALUE=11>November</OPTION>
<OPTION VALUE=12>December</OPTION>
</SELECT><BR><BR>
<SELECT NAME=Year>
<OPTION VALUE=2002>2002</OPTION>
<OPTION VALUE=2003>2003</OPTION>
<OPTION VALUE=2004>2004</OPTION>
</SELECT><BR><BR>
<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE='SUBMIT'>
</FORM>";
}
# End Body
?>