I have written the following script to creates a .ics file download based on a mySQL query.
$start = date('Ymd', strtotime($row['CourseStartDate']));
$end = date('Ymd', strtotime($row['CourseEndDate']));
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=Bookings$id.ics");
echo "BEGIN:VCALENDAR\n";
echo "PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN\n";
echo "VERSION:2.0\n";
echo "METHOD:PUBLISH\n";
echo "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
echo "BEGIN:VEVENT\n";
echo "CLASS:PUBLIC\n";
echo "CREATED:20091109T101015Z\n";
echo "DESCRIPTION:{$row['Attendees']}\n";
echo "DTEND:{$end}\n";
echo "DTSTAMP:20100109T093305Z\n";
echo "DTSTART:{$start}\n";
echo "LAST-MODIFIED:20091109T101015Z\n";
echo "LOCATION:{$row['CourseLocation']}\n";
echo "PRIORITY:5\n";
echo "SEQUENCE:0\n";
echo "SUMMARY:{$row['CourseTitle']}\n";
echo "TRANSP:OPAQUE\n";
echo "UID:".date('Ymd') . 'T' .date('His').rand();
echo "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n";
echo "X-MICROSOFT-CDO-IMPORTANCE:1\n";
echo "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n";
echo "X-MS-OLK-ALLOWEXTERNCHECK:TRUE\n";
echo "X-MS-OLK-AUTOFILLLOCATION:FALSE\n";
echo "X-MS-OLK-CONFTYPE:0\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
mySQL
$sql = "SELECT BookingID, CourseStartDate, CourseEndDate, CourseTitle,(' ',Forenames,' ', Surname) as Attendees, LastUpdated
FROM Bookings
GROUP BY CourseStartDate, CourseTitle
ORDER BY CourseStartDate DESC";
When I download the file it creates a perfect calendar event with everything targeted as planned, however it only returns one course, I'd like to be able to do this on a course by course basis, ie view a course and have the option to 'download to calendar' then run the script based on that course!?. I tried writing in an if
statement but to no avail. Where am I going wrong?!
If I understood, you should :
Use $_GET to pass the id of your course.
Example if you are viewing "Course #1" :
<a href="caltest.php?id=$course_id">Download to calendar</a>
Then add WHERE clause in your SQL query in caltest.php
:
WHERE CourseId = $_GET['id']
Note : Verify that $_GET['id']
is valid and use prepared statements for more security
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.