这是建立在上一个问题的基础上的: https ://stackoverflow.com/questions/15534272/interpreting-the-day-of-a-datetime-and-putting-it-into-a-relevant-div
本质上我有这张表:
Events Table
EventID | Start | End | Details
1 | 2013-03-18 09:00:00 | 2013-03-18 10:00:00 | Event is in room 6
2 | 2013-03-18 10:00:00 | 2013-03-18 11:00:00 | Event is in room 3
和这个专栏:
<div class="timetable-column-first">
<div class="timetable-row-start">Time</div>
<div class="timetable-row">9:00am</div>
<div class="timetable-row">10:00am</div>
</div>
<div class="timetable-column">
<div class="timetable-row-start">Monday</div>
<div class="timetable-row" id="mon-9"></div>
<div class="timetable-row" id="mon-10"></div>
</div>
我已经构建了这个 php 查询来获取我需要的信息:
function getEvents($weekNumStart, $weekNumEnd){
$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
if (!$mysqli) {
die('There was a problem connecting to the database.');
}
else {
if ($weekNumEnd == '') {
$weekNumEnd = $weekNumStart;
}
$query = $mysqli->prepare("SELECT EventID, DAYOFWEEK(Start) AS wday, Events.Start, HOUR(Start) AS sHour, HOUR(End) AS eHour, Events.End, Details, StartName FROM Events, Week WHERE StartName >= '$weekNumStart' AND StartName <= '$weekNumEnd' AND Events.Start >= StartWeek AND Events.Start <=EndWeek;");
$query->execute();
$query->bind_result($eventID, $dayofweek, $startDateTime, $startHour, $endHour, $endDateTime, $weekName);
while ($query->fetch()){
echo $eventID, $dayofweek, $startDateTime, $startHour, $endHour, $endDateTime, $weekName;
}
}
$mysqli->close();
}
问题是这个查询是在附加的 php 文件 /functions.php 中完成的,该文件包含在标题中。
我不知道如何更改此行:
echo $eventID, $dayofweek, $startDateTime, $startHour, $endHour, $endDateTime, $weekName;
这样它要么将每个数组返回到原始 index.php,然后我就可以使用 jquery 将它插入到我的 div id 的列和行中。因此,例如,细节在 div 中会像这样结束:
<div class="timetable-column">
<div class="timetable-row-start">Monday</div>
<div class="timetable-row" id="mon-9">1 - Event is in room 6</div>
<div class="timetable-row" id="mon-10">2 - Event is in room 3</div>
</div>
就目前而言,我的功能有效,从服务器回显所有单独的数据。
在 index.php 页面上,我只是这样称呼它:
getEvents($weekNumStart, $weekNumEnd);
我考虑过返回数组而不是回显,但这不会只返回很多行吗?因此,当我在带有列表的 index.php 页面上选择它时,($the data here) = getEvents($weekNumStart, $weekNumEnd);
我只会将第一个事件发回?