Hello:
I'm writing a script to create an event calendar. I have a table which contains a few events.
I was able to write some code which would grab the events from the table and place them in the calendar as links. If you click the event, the details of the event appear.
Each event should appear as a link in the box for the day for which that event is scheduled. For example, an event scheduled for May 4th should appear in the May 4th box.
Right now, my events appear as links at the top. You can see my result thus far by going to this URL:
http://www.summitwebcrafters.com/listing22.3.php
I can use help in fixing the code so my event links appear in the appropriate day within the calendar.
Below is the code for the main calendar and beneath that is the script which extracts the events from the table.
Thank you in advance for any and all help.
The main calendar script:
<?php
include "config.php";
$db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error());
$db_select = mysql_select_db ($DBName) or die (mysql_error());
$db_table = $TBL_PR . "events";
define("ADAY", (606024));
if (!checkdate($POST['month'], 1, $POST['year'])) {
$nowArray = getdate();
$month = $nowArray['mon'];
$year = $nowArray['year'];
} else {
$month = $POST['month'];
$year = $POST['year'];
}
$query = "SELECT event_id,event_title,event_day,event_time FROM $db_table WHERE event_month='$month' AND event_year='$year' ORDER BY event_time";
$query_result = mysql_query ($query);
while ($info = mysql_fetch_array($query_result))
{
$day = $info['event_day'];
$event_id = $info['event_id'];
$events[$day][] = $info['event_id'];
$event_info[$event_id]['0'] = substr($info['event_title'], 0);;
$event_info[$event_id]['1'] = $info['event_time'];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar:".$firstDayArray['month']." ".$firstDayArray['year'] ?></title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body>
<form method="post" action="<?php echo "$SERVER[PHP_SELF]"; ?>">
<form name="drop" method="post" action="<?php echo "$SERVER[PHP_SELF]"; ?>">
<select name="month" onChange="this.form.submit()">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October",
"November", "December");
for ($x=1; $x <= count($months); $x++) {
echo"<option value=\"$x\"";
if ($x == $month) {
echo " SELECTED";
}
echo ">".$months[$x-1]."";
}
?>
</select>
<select name="year" onChange="this.form.submit()"> >
<?php
for ($x=2000; $x<=2010; $x++) {
echo "<option";
if ($x == $year) {
echo " SELECTED";
}
echo ">$x";
}
?>
</select>
</form></td>
</tr>
</table>
<?php
$days = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
echo "<TABLE BORDER=1 CELLPADDING=5><tr>\n";
foreach ($days as $day) {
echo "<TD width=\"10%\" BGCOLOR=\"#CCCCCC\" ALIGN=CENTER><font face=\"verdana\" font size=\"1\"><strong>$day</strong>
</font></td>\n";
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
if ($dayArray['mon'] != $month) {
break;
} else {
echo "</tr><tr>\n";
}
}
if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month) {
echo "<td height=\"100\" valign=\"top\" align=\"right\"><font face=\"verdana\" font size=\"1\"> </td>\n";
} else {
echo "<td height=\"100\" valign=\"top\" align=\"right\">
<font face=\"verdana\" font size=\"1\">".$dayArray['mday']." </td>\n";
$start += ADAY;
}
if(isset($events[$dayArray['mday']]))
{
echo"<div alighn=\"left\">\n";
while (list($key, $value) = each ($events[$dayArray['mday']]))
{
echo "<a href=\"javascript:MM_openBrWindow('event.php?id=$value','','width=500,height=200');\">".$event_info[$value]['0']."</a><br>\n";
}
echo "</span></div>\n";
}
echo "</td>\n";
}
echo "</tr></table>";
?>
</body>
</html>
======
Script which extracts events from table (event.php)
<?
require_once("config.php");
$db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error());
$db_select = mysql_select_db ($DBName) or die (mysql_error());
$db_table = $TBL_PR . "events";
$query = "SELECT * FROM $db_table WHERE event_id='$_GET[id]' LIMIT 1";
$query_result = mysql_query ($query);
while ($info = mysql_fetch_array($query_result)){
$date = date ("l, jS F Y", mktime(0,0,0,$info['event_month'],$info['event_day'],$info['event_year']));
$time_array = split(":", $info['event_time']);
$time = date ("g:ia", mktime($time_array['0'],$time_array['1'],0,$info['event_month'],$info['event_day'],$info['event_year']));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHPCalendar - <? echo $info['event_title']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="cal.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="480" height="180" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="100">
<table width="480" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><span class="eventwhen"><u><? echo $date; ?></u></span><br>
<br> <br> </td>
</tr>
<tr>
<td><span class="event">Event Time</span></td>
</tr>
<tr>
<td><span class="eventdetail"><? echo $info['event_time']; ?></span><br>
<br></td>
</tr>
<tr>
<td><span class="event">Event Title</span></td>
</tr>
<tr>
<td><span class="eventdetail"><? echo $info['event_title']; ?></span><br>
<br></td>
</tr>
<tr>
<td><span class="event">Event Description</span></td>
</tr>
<tr>
<td><span class="eventdetail"><? echo $info['event_desc']; ?></span><br></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<? } ?>