我正在构建预订系统,并选择使用时间戳将预订存储在我的mysql数据库中。然而,用户可以预约2或3个插槽,例如:根据时间戳按日期和时间分组条目
9:00 - 9:30
9:30 - 10:00
10:00 - 10:30
或者他们可以只预订单个插槽。
我想告诉用户,但其中通过组的时限作出的预订,因此,例如在它上面显示的时间应显示9:00 - 10:30,而不是列出3项。
每个预订存储有bookingFrom和bookingUntil作为timetamp。我已经设法让它工作2次预订(例如9:00-9:30和9:30-10:00只显示为9:00-10:00),但如果有中间入口,我是在如何使这项工作中挣扎。
任何想法?我使用PHP/MySQL的
表模式
bookingID,用户ID,bookingFrom(INT - UNIX时间戳),bookingUntil(INT - UNIX时间戳)
CREATE TABLE IF NOT EXISTS `dma_bookings` (
`bookingID` int(11) NOT NULL AUTO_INCREMENT,
`userID` int(11) NOT NULL,
`bookingFrom` int(11) NOT NULL,
`bookingUntil` int(11) NOT NULL,
`roomID` int(11) NOT NULL,
PRIMARY KEY (`bookingID`),
KEY `userID` (`userID`,`bookingFrom`,`bookingUntil`),
KEY `roomID` (`roomID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=98 ;
--
-- Dumping data for table `dma_bookings`
--
INSERT INTO `dma_bookings` (`bookingID`, `userID`, `bookingFrom`, `bookingUntil`, `roomID`) VALUES
(95, 1, 1317362400, 1317364199, 1),
(96, 1, 1317364200, 1317365999, 1),
(97, 1, 1317366000, 1317367799, 1);
到目前为止的代码(道歉很凌乱!):
$bookingArray = $data['bookingInfo'];
$bookingCleanArray = array();
$reversedArray = array_reverse($data['bookingInfo']);
$currentItemIndex=0;
$nextItemIndex=1;
foreach($reversedArray as $booking){
echo "<hr>BookingID: ".$booking['bookingID']."<br/><br/>";
$bookingFromMinusOne=$booking['bookingFrom']-1;
if($bookingFromMinusOne==$data['bookingInfo'][$nextItemIndex]['bookingUntil']){
//The current booking is part of a multiple booking range
$bookingArray[$nextItemIndex]['bookingUntil']=$booking['bookingUntil'];
unset($bookingArray[$currentItemIndex]);
}else{
echo "Single booking<br/>";
}
$currentItemIndex++;
$nextItemIndex++;
}
把表模式和数据的一些想法和你需要从查询中得到什么结果。 – rahularyansharma
更新了最初的帖子,谢谢! – Amo