我编写了以下脚本来创建基于mySQL查询的.ics文件下载。
$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";
当我下载文件时,它会创建一个完美的日历活动,其中包含按计划进行的所有目标,但是它只返回一个课程,我希望能够逐个课程地进行,即查看课程并可以选择下载到日历'然后根据该课程运行脚本!?我尝试用if
语句写作但无济于事。我哪里错了?!
答案 0 :(得分:0)
如果我理解,你应该:
使用$ _GET传递课程的ID。
如果您正在观看"课程#1" :
<a href="caltest.php?id=$course_id">Download to calendar</a>
然后在caltest.php
中的SQL查询中添加WHERE子句:
WHERE CourseId = $_GET['id']
注意:验证$_GET['id']
是否有效,并使用prepared statements获得更高的安全性