Ben aynen böyle verilerle bir tablo var:
ID Heading Description Time Location Start_Date End_Date 63 Wed Serv Small group 19:00:00 null 2010-10-13 null 70 Fall Harvest Calvary null Pepin, Wi 2010-10-30 null
Benim Takvim doğru tarihlerde etkinlikleri gösterir, ancak iki olay için zamanı 07:00 ve ben nedenini anlamaya olamaz. Bir olay için zaman sıfır ama yine takvimde 19:00 söylüyor.
$ Time denilen değişken bir göz atın
Benim komut şudur:
<?php
//if the current page is empty, set the date variable to the current time, else set the date variable to the currentpage
$date = empty($_GET['currentpage']) ? time() : strtotime($_GET['currentpage']);
//This puts the day, month, and year in separate variables
$day = date('d', $date);
$month = date('m', $date);
$year = date('y', $date);
$bigYear = date('Y', $date);
$first_day = mktime(0, 0, 0, $month, 1, $year); //we need to generate the first day of the month
$month_name = date('F', $first_day); //get the current month's full spelling
$day_of_week = date('D', $first_day); //find out what day of the week the first day of the month falls on
$prevM = getDate(mktime(0, 0, 0, $month-1, 1, $year)); //gets an associative array of the previous month
$nextM = getDate(mktime(0, 0, 0, $month+1, 1, $year)); //gets an associative array of the next month
$prevMonth = "{$prevM['year']}-{$prevM['mon']}"; //gets the actual previous month's name. Subtracts the year from the month so you're not stuck in the current year.
$nextMonth = "{$nextM['year']}-{$nextM['mon']}"; //gets the actual next month's name. Subtracts the year from the month so you're not stuck in the current year.
$day_count = 1; //counts the days up to 7 so we know when to start a new week
$day_num = 1; //counter for the total number of days in the month
$dates = new dates(); //instantiate the dates object
//once we know what day of the week it falls on, we know how many blank days before it occur.
switch($day_of_week) {
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sat": $blank = 6; break;
}
//then we need to determine how many days are in the month
$days_in_month = cal_days_in_month(0, $month, $year);
//Here we start building the table heads
echo "<table>".PHP_EOL;
echo "\t\t\t\t<thead>".PHP_EOL;
echo "\t\t\t\t\t<tr>".PHP_EOL;
echo "\t\t\t\t\t\t<th colspan=2 class=\"noBorder\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$prevMonth'>«</a></th>";
echo "\t\t\t\t\t\t<th colspan=3 class=\"noBorder\"><strong>$month_name"." "."$bigYear</strong></th>";
echo "\t\t\t\t\t\t<th colspan=2 class=\"noBorder\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$nextMonth'>»</a></th>";
echo "\t\t\t\t\t</tr>".PHP_EOL;
echo "\t\t\t\t\t<tr>".PHP_EOL;
echo "\t\t\t\t\t\t<th>Sun</th>".PHP_EOL;
echo "\t\t\t\t\t\t<th>Mon</th>".PHP_EOL;
echo "\t\t\t\t\t\t<th>Tue</th>".PHP_EOL;
echo "\t\t\t\t\t\t<th>Wed</th>".PHP_EOL;
echo "\t\t\t\t\t\t<th>Thu</th>".PHP_EOL;
echo "\t\t\t\t\t\t<th>Fri</th>".PHP_EOL;
echo "\t\t\t\t\t\t<th>Sat</th>".PHP_EOL;
echo "\t\t\t\t\t</tr>".PHP_EOL;
echo "\t\t\t\t</thead>".PHP_EOL;
echo "\t\t\t\t<tbody>".PHP_EOL;
echo "\t\t\t\t\t<tr>".PHP_EOL;
//first we take care of those blank days
while($blank > 0)
{
echo "\t\t\t\t\t\t<td> </td>".PHP_EOL;
$blank = $blank-1;
$day_count++;
}
//while we're not at the last day of the month...
while($day_num <= $days_in_month)
{
//get the events from the table
foreach($dates->getRows() as $results)
{
//parse the date field
$eventStartYear = substr($results['start_date'], 0, 4);
$eventStartMonth = substr($results['start_date'], 5, 2);
$eventStartDay = substr($results['start_date'], 8, 2);
$eventEndYear = substr($results['end_date'], 0, 4);
$eventEndMonth = substr($results['end_date'], 5, 2);
$eventEndDay = substr($results['end_date'], 8, 2);
$heading = $results['heading'];
$description = $results['description'];
$time = strftime("%l:%M %P", $results['time']);
//if the event fields are not null and the event day is equal to the day counter, and the event month and year are equal to the current month
// AND it is a multiple day event
if(!is_null($eventStartDay) && !is_null($eventStartMonth) && !is_null($bigYear) && !is_null($eventEndDay) && !is_null($eventEndMonth) && !is_null($eventEndYear) && $day_num == $eventStartDay && $month == $eventStartMonth && $bigYear == $eventStartYear)
{
$currentDay = $eventStartDay;
//while the current day is less than or equal to the end day of the event
while($currentDay <= $eventEndDay)
{
//echo "id = ".$id."<br />";
//echo "time = ".$time."<br />";
//echo "time2 = ".$time2."<br />";
echo "\t\t\t\t\t\t<td><a href=\"displayEvent.php?id=$id\">$day_num<h4>".$heading."</h4><h5>".$time."</h5></a></td>".PHP_EOL;
$currentDay++;
$day_num++;
$day_count++;
}
}
if(!is_null($eventStartDay) && !is_null($eventStartMonth) && !is_null($bigYear) && $day_num == $eventStartDay && $month == $eventStartMonth && $bigYear == $eventStartYear)
{
//echo "id = ".$id."<br />";
//echo "time = ".$time."<br />";
//echo "time2 = ".$time2."<br />";
echo "\t\t\t\t\t\t<td><a href=\"displayEvent.php?id=$id\">$day_num<h4>".$heading."</h4><h5>".$time."</h5></a></td>".PHP_EOL;
$day_num++;
$day_count++;
}
//make sure we start a new row every week
if($day_count > 7)
{
echo "\t\t\t\t\t</tr>".PHP_EOL;
echo "\t\t\t\t\t<tr>".PHP_EOL;
$day_count = 1;
}
}
//print days that don't have events
echo "\t\t\t\t\t\t<td><a href=\"noEvent.php\">$day_num</a></td>".PHP_EOL;
$day_count++;
$day_num++;
//make sure we start a new row every week
if($day_count > 7)
{
echo "\t\t\t\t\t</tr>".PHP_EOL;
echo "\t\t\t\t\t<tr>".PHP_EOL;
$day_count = 1;
}
}
//finish the table with some blanks if needed
while($day_count > 1 && $day_count <= 7) {
echo "\t\t\t\t\t\t<td> </td>".PHP_EOL;
$day_count++;
}
echo "\t\t\t\t\t</tr>".PHP_EOL;
echo "\t\t\t\t</tbody>".PHP_EOL;
echo "\t\t\t</table>".PHP_EOL;
?>