0

I have no problem adding a single event to the calendar. But I am having a problem when adding multiple events with the foreach. Where am I making a mistake? Can you help me?(The dates I pulled from the database are in Y-m-d format.)

errror is "Some events in the calendar file could not be added. The calendar file may be corrupt."

<?php
require_once("zapcallib.php");
include('../dbcon/db.php');

$ical = "BEGIN:VCALENDAR\n
VERSION:2.0\n
PRODID:-//[YOUR WEBSITE], Inc.//EN\n";

foreach($db->query("SELECT * FROM rezervasyondurumu where evid='1'") as $listele) {
  $baslangic= $listele['baslangic'];
  $bitis= $listele['bitis'];
  $ical .= "\nBEGIN:VEVENT";
  $ical .= "\nUID: ".$listele['aciklama'] ." fewofethiye.com";
  $ical .= "\nDTSTAMP:" . date('Ymd');
  $ical .= "\nORGANIZER:catalog@example.com";
  $ical .= "\nDTSTART:".date("Ymd", strtotime($baslangic));
  $ical .= "\nDTEND:".date("Ymd", strtotime($bitis));
  $ical .= "\nSUMMARY:".$listele['aciklama'];
  $ical .= "\nDESCRIPTION:" .$listele['aciklama'];
  $ical .= "\nEND:VEVENT";

}

$ical .= "\nEND:VCALENDAR";

header("Content-type: text/calendar; charset=utf-8");
header("Content-Disposition: inline; filename=calendar.ics");
echo $ical;
?>
leatred
  • 1
  • 2
  • 1
    What have you done to try debug this? At the very least I would start with getting the db results separately and dumping them, so that you know the quality of the array being passed to the foreach. Then I would not be trying to add them to a calendar until the ics file output looked good. One can open the output in a text editor and visually look to see what's going on. One can also put the .ics file through ALL the icalendar validators that you can find & see what they pickup (they vary in this). – anmari Mar 23 '21 at 02:37
  • As @anmari said, open the .ics file you generate in a text editor and compare it to a known good file (see [this SO question](https://stackoverflow.com/questions/1823647/grouping-multiple-events-in-a-single-ics-file-icalendar-stream/1830655) for an example). – superhawk610 Mar 23 '21 at 03:09

0 Answers0