I decided the try to make my own event calendar and the actual calendar displays/operates wonderfully but I cannot figure out how to get events to display! I have the events stored in my database along with their correct date, title, description. How can I have these events display in their correct day?
Here is my calendar so far
[code=php]<?php
$host = “localhost”;
$username = “example”;
$password = “example”;
$database = “example”;
$connection = mysql_connect($host, $username, $password);
mysql_connect($host, $username, $password) OR DIE (‘Unable to connect to database! Please try again later.’);
mysql_select_db($database);
// Collect the current date or desired date
if (isset($_GET[‘view’])){
$getDate = $_GET[‘view’];
$viewDate = explode(‘/’, $getDate);
$month = $viewDate[0];
$year = $viewDate[1];
}else{
$month = date(“m”);
$year = date(“Y”);
}
// Collect information on the current date or desired date
$date = mktime(0, 0, 0, $month, 01, $year);
$monthName = date(“F”, $date);
$totalDays = date(“t”, $date);
$startDay = date(“w”, $date);
// Find today
$today = date(“m”) . date(“j”) . date(“Y”);
// Generate previous link
$previous = $month – 1;
if ($month == 01){
$previousYear = $year – 1;
}else{
$previousYear = $year;
}
$previousDate = mktime(0, 0, 0, $previous, 01, $year);
$previousMonth = date(“F”, $previousDate);
$previousNumberProper = date(“m”, $previousDate);
// Generate next link
$next = $month + 1;
if ($month == 12){
$nextYear = $year + 1;
}else{
$nextYear = $year;
}
$nextDate = mktime(0, 0, 0, $next, 01, $year);
$nextMonth = date(“F”, $nextDate);
$nextNumberProper = date(“m”, $nextDate);
// Find needed calendar TD’s
$monthTotal = $startDay + $totalDays;
if ($monthTotal <= 28){
$calendarTD = 28;
}
if ($monthTotal > 28 && $monthTotal < 36){
$calendarTD = 35;
}
if ($monthTotal >= 36){
$calendarTD = 42;
}
// Set calendar counts
$printTR = 1;
$printTD = 1;
$day = 1;
// Get those events!
$getEvent = mysql_query(“SELECT * FROM example WHERE month=’$month’ AND year=’$year'”);
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Greyfish Creative</title>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″/>
<link rel=”stylesheet” type=”text/css” media=”screen” href=”calendar.css”/>
</head>
<body>
<?php
echo “<table id=”calendar”>n”;
echo “<tr id=”explore”><td id=”previous” class=”exploreLink”><a href=”index.php?view=$previousNumberProper/$previousYear”>$previousMonth</a></td><td id=”month” colspan=”5″>$monthName</td><td id=”next” class=”exploreLink”><a href=”index.php?view=$nextNumberProper/$nextYear”>$nextMonth</a></td></tr>n”;
echo “<tr id=”days”><td>Sunday</td><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday</td><td>Saturday</td></tr>n”;
while ($printTD <= $calendarTD){
if ($printTR == 1){
echo “<tr class=”week”>”;
}
if ($printTD <= $startDay + $totalDays){
if ($printTD > $startDay){
$currentDay = $month . $day . $year;
if ($currentDay == $today){
echo “<td class=”today”>”;
echo $day;
echo “</td>”;
}else{
echo “<td class=”monthDay”>”;
echo $day;
echo “</td>”;
}
$day++;
}else{
echo “<td class=”nonmonthDay”></td>”;
}
}
if ($printTD > $startDay + $totalDays){
echo “<td class=”nonmonthDay”></td>”;
}
if ($printTR == 7){
echo “</tr>n”;
$printTR = 1;
}else{
$printTR++;
}
$printTD++;
}
echo “</table>n”;
?>
</body>
</html>