Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic ical created from database not working
    text
    copied!<p>I built a site in PHP 5 and MySQL with a table that keeps track of scheduled photo shoots. I want to push out a feed of those scheduled "events" into an ical file.</p> <p>I originally <a href="https://stackoverflow.com/questions/1463480/how-can-i-use-php-to-dynamically-publish-an-ical-file-to-be-read-by-google-calend">asked this question</a> and got a good answer from <a href="https://stackoverflow.com/users/11354/s-gehrig">S. Gehrig</a>. I got a sample ical file working, and updating regularly in Google Calendar whenever I manually adjusted the file in Dreamweaver. However, now that I've added dynamic PHP pulling from the database, it won't work.</p> <p>Here's the PHP:</p> <pre><code>&lt;?php require_once('../../_includes/initialize.php'); $ical = " BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN "; $slots = Slot::find_all(); foreach($slots as $slot) { $job = Job::find_by_id($slot-&gt;job_id); $start_stamp = strtotime($slot-&gt;start); $end_stamp = strtotime($slot-&gt;endtime); $dtstart = gmdate('Ymd', $start_stamp).'T'. gmdate('His', $start_stamp) . "Z"; // converts to UTC time $dtend = gmdate('Ymd', $end_stamp).'T'. gmdate('His', $end_stamp) . "Z"; // converts to UTC time $summary = $job-&gt;title; $ical .= " BEGIN:VEVENT UID:" . $slot-&gt;id . "@homewoodphoto.jhu.edu DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z DTSTART:" . $dtstart . " DTEND:" . $dtend . " SUMMARY:" . $summary . " END:VEVENT "; } $ical .= " END:VCALENDAR"; //set correct content-type-header header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: inline; filename=homewoodphoto_master.ics'); echo $ical; exit; ?&gt; </code></pre> <p>The output of this file is exactly the same as the manual, hard-coded version that I have working, as far as I can tell. Can anyone see why this isn't working????</p> <p>PS Here is the code of the file that IS working -- I just posted it on my server and subscribed via URL in Google Calendar. When I hardcoded in the 2nd event, it showed up shortly in Google Calendar on its own.</p> <pre><code>&lt;?php $ical = "BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN BEGIN:VEVENT UID:" . md5(uniqid(mt_rand(), true)); . "@yourhost.test DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z DTSTART:20090925T170000Z DTEND:20090928T035959Z SUMMARY:Bastille Day Party END:VEVENT BEGIN:VEVENT UID:" . md5(uniqid(mt_rand(), true)); . "@yourhost.test DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z DTSTART:20090929T170000Z DTEND:20090930T035959Z SUMMARY:Camping Trip END:VEVENT END:VCALENDAR"; //set correct content-type-header header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: inline; filename=calendar.ics'); echo $ical; exit; ?&gt; </code></pre> <p>HELP!</p> <p>A commenter suggested I test by removing the headers and echoing the $ical var. Here are the results of that test, with line breaks added for your convenience:</p> <pre><code>BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN BEGIN:VEVENT UID:21@homewoodphoto.jhu.edu DTSTAMP:20090929T212141Z DTSTART:20091001T230000Z DTEND:20091001T230000Z SUMMARY:little title END:VEVENT BEGIN:VEVENT UID:22@homewoodphoto.jhu.edu DTSTAMP:20090929T212141Z DTSTART:20090926T230000Z DTEND:20090927T010000Z SUMMARY:A big photo shoot END:VEVENT BEGIN:VEVENT UID:23@homewoodphoto.jhu.edu DTSTAMP:20090929T212141Z DTSTART:20091003T230000Z DTEND:20091004T010000Z SUMMARY:A big photo shoot END:VEVENT END:VCALENDAR </code></pre> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload