[英]MySQL Query, GET(id)?!
I have written the following script to creates a .ics file download based on a mySQL query. 我编写了以下脚本,以基于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 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. 我尝试在
if
语句中编写,但无济于事。 Where am I going wrong?! 我要去哪里错了?
If I understood, you should : 如果我理解,您应该:
Use $_GET to pass the id of your course. 使用$ _GET通过您的课程ID。
Example if you are viewing "Course #1" : 例如,如果您正在查看“课程1”:
<a href="caltest.php?id=$course_id">Download to calendar</a>
Then add WHERE clause in your SQL query in caltest.php
: 然后在
caltest.php
的SQL查询中添加WHERE子句:
WHERE CourseId = $_GET['id']
Note : Verify that $_GET['id']
is valid and use prepared statements for more security 注意:验证
$_GET['id']
有效,并使用准备好的语句以提高安全性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.