Hi All,
i have a calendar app on my site that displays a users diary of events, i've hit a problem on how to get this to show a block of dates with the same event - holiday for two weeks, the user would have to add this event to each date individually instead of just a from and to date. I have adjust my mysql database now to include an end date for an event (defaulting to the dame start date for 1 day events), but how do i show the start and end dates?
Here is my code to retrieve the info - please note that i am a beginner and this is a script i have found and modified but it has taken ages to get my head round!
Many thanks for reading this - i hope someone can help!
i have a calendar app on my site that displays a users diary of events, i've hit a problem on how to get this to show a block of dates with the same event - holiday for two weeks, the user would have to add this event to each date individually instead of just a from and to date. I have adjust my mysql database now to include an end date for an event (defaulting to the dame start date for 1 day events), but how do i show the start and end dates?
Here is my code to retrieve the info - please note that i am a beginner and this is a script i have found and modified but it has taken ages to get my head round!
Code:
<?php
<?php
include ('./connections.php');
// Now we need to define "A DAY", which will be used later in the script:
define("ADAY", (60*60*24));
// The rest of the script will stay the same until about line 82
if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
$nowArray = getdate();
$month = $nowArray['mon'];
$year = $nowArray['year'];
} else {
$month = $_POST['month'];
$year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Craig's Schedule: ".$firstDayArray['month']." " . $firstDayArray['year']; ?></title>
<link rel="stylesheet" href="../css/default.css" type="text/css">
<link rel="stylesheet" href="../css/admin.css" type="text/css">
</head>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=500,height=500');
event_popupWin.opener = self;
}
</script>
<body>
<div id="container">
<div id="content">
<div id="content_leaves">
<div id="calendar">
<h1>Select a Month/Year</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?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]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<=2010; $x++){
echo "<option";
if ($x == $year){
echo " selected";
}
echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<p> </p>
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"0\" cellpadding=\"3\">\n";
foreach ($days as $day) {
echo "<th><strong>$day</strong>\n";
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
if ($dayArray["mon"] != $month) {
break;
} else {
echo "</th>
<tr>\n";
}
}
if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
echo "<td> </td>\n";
} else {
$chkEvent_sql = "SELECT EventTitle, EventVenue FROM $tbl_name1 WHERE month(EventDate) = '".$month."' AND dayofmonth(EventDate) = '".$dayArray["mday"]."' AND year(EventDate) = '".$year."' ORDER BY EventDate";
$chkEvent_res = mysql_query($chkEvent_sql, $mysql) or die(mysql_error($mysql));
if (mysql_num_rows($chkEvent_res) > 0) {
$event = "<br />";
while ($ev = mysql_fetch_array($chkEvent_res)) {
$event .= "<div class=\"calendar_event\">".stripslashes($ev["EventTitle"])."</div> <div class=\"calendar_venue\">".stripslashes($ev["EventVenue"])."</div>";
}
mysql_free_result($chkEvent_res);
} else {
$event = " ";
}
echo "<td valign=\"top\"><a href=\"javascript:eventWindow('./event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');\" class=\"calendar\">".$dayArray["mday"]."</a><br/>".$event."</td>\n";
unset($event);
$start += ADAY;
}
}
echo "</tr>
</table>";
mysql_close($mysql);
?>
</div> <!-- calendar -->
</div><!-- content leaves -->
<div id="footer">
<? //include('includes/footer.php'); ?>
</div>
</div><!-- content -->
</div><!-- container -->
</body>
</html>