日历中的mysql数据检查是否预订
我有一个包含物品预订的数据库。所有预订都有: ID 、项目 ID、 personWhoBookedId、 time_from (unixtime) 、 time-to(unixtime) 。
我喜欢显示每天每小时的时间安排,并为预订项目的时间着色并显示该时间范围内的 personWhoBookedID。
:
room1:
5:00 - 6:00: free
6:00 - 7:00: booked by[person]
8:00 - 9:00:free
等
room 2:
5:00 - 6:00: free
6:00 - 7:00: booked by[person]
8:00 - 9:00: booked by[person]
像
此时,我使用 mysql 迭代现有的项目,然后使用 mysql 检查每个时间范围是否有等于 itemID 的预订,并且 timeis 在提到的时间范围和时间范围之间
这可行,但确实是对数据库进行大量查询。
为了提高性能,我认为我最好首先获取所有预订并将它们存储在多维数组中,如下所示:
$allreservationsperday = mysql_query("select id, personid, itemid, time_from, time_to FROM reservations where time_from >= '$unixfrom' and time_to < '$unixto'");
while($reservationarray = mysql_fetch_array($allreservationsperday)){
$res[$reservationarray ["id"]]["personid"] = $reserveringenarray["personid"];
$res[$reservationarray ["id"]]["itemid"] = $reserveringenarray["itemid"];
$res[$reservationarray ["id"]]["time_from"] = $reserveringenarray["time_from"];
$res[$reservationarray ["id"]]["time_to"] = $reserveringenarray["time_to"];
}
然后通过 for 循环显示时间线以循环一天中的各个小时 但我不知道如何每小时检查刚刚形成的数组中是否有预订。
非常欢迎任何帮助! 杰罗恩
I have a database with reservations for items. All reservations have an: ID , item ID, personWhoBookedId, time_from (unixtime) , time-to(unixtime).
I like to display a day per day time schedual from hour to hour, and colour the timethat an item is booked and display the personWhoBookedID on that timeframe.
like:
room1:
5:00 - 6:00: free
6:00 - 7:00: booked by[person]
8:00 - 9:00:free
and
room 2:
5:00 - 6:00: free
6:00 - 7:00: booked by[person]
8:00 - 9:00: booked by[person]
etc
At this time I iterate through the existing items with mysql, then check per timeframe with mysql if there is a booking that equals itemID and timeis between the mentioned timeframe of time-from and time-to
This works but is does a lot of queries on the database.
To increase performance I think I better frist get all the reservations and store them in a multi dimensional array, like this:
$allreservationsperday = mysql_query("select id, personid, itemid, time_from, time_to FROM reservations where time_from >= '$unixfrom' and time_to < '$unixto'");
while($reservationarray = mysql_fetch_array($allreservationsperday)){
$res[$reservationarray ["id"]]["personid"] = $reserveringenarray["personid"];
$res[$reservationarray ["id"]]["itemid"] = $reserveringenarray["itemid"];
$res[$reservationarray ["id"]]["time_from"] = $reserveringenarray["time_from"];
$res[$reservationarray ["id"]]["time_to"] = $reserveringenarray["time_to"];
}
and then display the timeline by a for Loop to loop through the hours of the day
But I cannot figure out how to check per hour if there is a reservation in the just formed array.
Any help most welcome!
jeroen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是循环遍历它们并检查行中下一个值的差异?
当然,在比较之前您还必须检查 $res[$key+1] 是否已设置。
just loop through them and check for differences on the next value in line?
of course you vill have to check if $res[$key+1] isset also before comparison.
@乔纳兹:
我不知道如何将其融入脚本中。
目前我尝试了这个(用于船舶租赁的概述):
以下脚本的预览位于此测试站点
@jonaz:
I don't see how to fit this into the script.
Currently I tried this (for an overview for boat rentals):
A preview of the script below is at this test site