PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi,
this is my first topic in this forum :)
I'm having some trouble with iCalReader. I want to display the upcoming dates, and in this case only the first 6 dates. But the problem is that with the code shown below, it counts 6 dates of all the dates, not only the upcoming ones. I hope you understand.
// These define() lines go at the top of the script
define('DTSTART', 'DTSTART;TZID=Europe/Oslo');
define('MAX_EVENTS', 6);
// Use the DTSTART constant in the compare_date() function
// Get and sort the events here
// This needs to be calculated only once, so put it outside the loop
$today = date('Ymd');
// Save the count to a variable to avoid unnecessary calculations
$count = count($events);
// Loop through all events until either there are no more events or
// the maximum number of recent events has been found
for ($row = 0, $hits = 0; $row < $count && $hits < MAX_EVENTS; $row++) {
// It's possible that some events will not have the appropriate key,
// so skip those events
if (! array_key_exists(DTSTART, $events[$row])) {
continue;
}
$date = substr($events[$row][DTSTART], 0, 8);
if ($date >= $today) {
// Increment the number of events found
$hits++;
// Move these operations inside this block to avoid unnecessary calculations
$year = substr($events[$row][DTSTART], 0, 4);
$month = substr($events[$row][DTSTART], 4, 2);
$day = substr($events[$row][DTSTART], 6, 2);
//$time = substr($events[$row][DTSTART], 9, 4); // Unused?
// This looks cleaner (in my opinion), but the format does not matter
echo '<tr>'
. '<td class="summary">' . $events[$row]['SUMMARY'] . '</td>'
. '<td class="date">'
. '<span class="day">' . $day . '/</span>'
. '<span class="month">' . $month . '/</span>'
. '<span class="year">' . $year . '</span>'
. '</td>'
. '</tr>' . "\n";
}
}
It's perfect for bands and such! You can set iCal to publish a calendar automatic, so then the artist/label don't have to worry about updating their webpage. I've used it here: http://www.brilliance.no And they love it.