预订系统日期 [英] Reservation system dates

查看:85
本文介绍了预订系统日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题,以 PHP& Mysql 。我已阅读如何在酒店预订系统中实施检查可用性还有一些,但他们似乎不同。

I have problem thinking this trough with PHP & Mysql. I have read How to implement check availability in hotel reservation system and some more but they seem different.

我必须建立一个预订系统,可以预订6小时的可用房间,所以当用户做一个在24/04/2012的日期预约,然后他选择出租的开始时间(00:00-06:00,06:00-12:00,12:00-18:00, 18:00-24:00)。以及用户想租房间的总时数(6,12,18等)。

I have to make a reservation system on which a converence room can be booked for 6hours minimal, so when a user make a reservation on a date e.g 24/04/2012 he then selects the start time of the rental (00:00-06:00, 06:00-12:00, 12:00-18:00,18:00-24:00). And the total number of hours(6,12,18 etc..) the user wants to rent the room.

日期存储为整数(timestamp)。

The date is stored as a integer(timestamp).

我有两个问题;我不知道如何收到房间仍然预订的一个月的所有可能的日子,以及如何检查是否可以进行新的预订。

I have two problems with this; I don´t know how to receive all possible days of a month on which the room is still up for reservation and how to check if a new reservation is possible.

我知道如何计算用户输入的开始日期和结束日期,但是我无法找到正确的 mysql查询 php检查

I know how to calculate the start date and end date on the users input but I cant find the correct mysql query or php check for availability.

这可能很简单,但不知何故,因为结束日期总是变量我只是找不到答案。

It's probably really simple but somehow because the end date is always variable I just cant find the answer.

提前感谢!

编辑表格结构:预订


id  int(11)         
user_id int(11)     
reservation_name    varchar(255)    
start_date  int(11)         
end_date    int(11)         

我相信预订是唯一一个相关的

I believe reservations is the only one relevant

推荐答案

你会发现这很难在MySQL中生成可用日期列表。我建议您选择所需月份内预定日期的有序列表,然后在PHP中跳过该日期的所有日期,如果它与您的MySQL查询中的下一个预定日期匹配,则跳过该日期。 此问题的答案将有助于您构建您要在PHP中循环的日期。在伪代码中:

You'll find it's pretty difficult to generate a list of available days in MySQL. I recommend instead that you select an ordered list of booked days within your desired month, then loop over all days of that month in PHP skipping the day if it matches the next booked day from your MySQL query. The answer to this question will help you to build the dates over which you want to loop in PHP. In pseudocode:

$booked_days = sql(select all booked days in month order by day);
for each $day in month {
   if $day != current($booked_days) {
      // $day is not booked
   } else advance_next($booked_days);
}

要检查是否可以进行新的预约,您可能需要查看在今天早些时候,我回答一个非常相似的问题

To check if a new reservation is possible, you might want to have a look at my answer to a very similar question earlier today.

这篇关于预订系统日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆