简体   繁体   English

PHP / MySQL预订系统

[英]PHP/MySQL Reservation System

I'm currently working on an Equipment Reservation System for my school. 我目前正在为学校使用设备预订系统。

Here's basically what my tables look like: 这基本上是我的表的样子:

tblEquipment: tblEquipment:

id    name          description
      1   Camera        Takes pictures
      2   Projector     Projects images
      3   Stereo        Plays music

tblEvents: tblEvents:

id       equipmentID        start             end
       1          2,3           1251312300     1251315900    //Should I use comma delimited entries for equipmentID?   
       2           1            1251312300     1251315900

Regarding my project, I have a couple of questions: 关于我的项目,我有几个问题:

1) If multiple pieces of equipment are being reserved, (which will happen more times than not) should the "equipmentIDs" be comma delimited in the equipmentID field? 1)如果保留了多台设备,(设备发生的次数将多于不多),是否应在equipmentID字段中用逗号分隔“ equipmentID”?

2) Currently, when a user makes a reservation, they first select their "requested times", then are presented with available items at that time. 2)当前,当用户进行预订时,他们首先选择他们的“请求时间”,然后在那时向他们显示可用的项目。 Here's what I am using for that query: 这是我用于该查询的内容:

$start = //user's requested time
$start = //user's requested time

SELECT equipmentID FROM tblEvents
 WHERE ($start >= start && $start <= end) 
 OR ($end >= start && $end <= end)
 OR ($start <= start && $end >= end

 while($row = mysql_fetch_array($data)) {

  echo $row['equipmentID'];  //Would echo something like: 
  echo "<br>";               //    2,3
                            //    1

 }

My question is this: 我的问题是这样的:

How can I take the 'results' of the above query to then re-query the 'tblequipment' table, but exclude the items that were in the 'results' above (because they would not be available). 如何获取上述查询的“结果”,然后重新查询“故障诊断”表,但排除上面“结果”中的项目(因为它们将不可用)。 Keeping in mind, that my query above may return multiple rows. 请记住,我上面的查询可能返回多行。

Any help on this would be great, thanks! 在这方面的任何帮助将是巨大的,谢谢!

Regarding #1: No! 关于#1:不! No, no, no, no, no! 不,不,不,不,不! If you have multiple pieces of equipment being reserved, then you should have multiple rows in the reservations table (what looks like tblEvents here). 如果要保留多台设备,那么在保留表中应该有多 (这里看起来像tblEvents )。 To avoid duplicating the other fields in tblEvents , you'd typically create a third table, perhaps tblEventEquipment that simply lists what equipment belongs with what event. 为了避免重复tblEvents其他字段,通常会创建第三个表,也许是tblEventEquipment ,该表仅列出了哪个设备属于哪个事件。

If you need a comma-separated list for the purposes of output (which doesn't seem likely), you can always generate one with GROUP_CONCAT() , but inside the table you want one row per reserved piece of equipment. 如果出于输出目的而需要用逗号分隔的列表(似乎不太可能),则始终可以使用GROUP_CONCAT()生成一个列表,但是在表内部,每个保留的设备都需要一行。 Otherwise, SQL cannot effectively (or efficiently) determine what equipment is reserved at a particular time. 否则,SQL无法有效(或有效)确定在特定时间保留了哪些设备。

Regarding #2, you want a query like: 关于#2,您需要一个查询,例如:

SELECT * 
FROM tblEquipment
WHERE NOT EXISTS (
  SELECT 1 
  FROM tblEvents 
  WHERE tblEvents.equipmentID = tblEquipment.equipmentID
    AND $end >= start AND $start <= end
)

This selects equipment for which there isn't a reservation. 这将选择没有预订的设备。 Note that I simplified your logic for determining whether the equipment is reserved or not by doing just two comparisons. 请注意,通过进行两次比较,我简化了确定设备是否保留的逻辑。

Finally, an unrelated note: I recommend strongly against storing timestamps as integers in the database table. 最后,一个不相关的注释:我强烈建议不要将时间戳记作为整数存储在数据库表中。 Use MySQL's built-in DATETIME type. 使用MySQL的内置DATETIME类型。 If you need to convert to/from a timestamp, you can use the UNIX_TIMESTAMP() and FROM_UNIXTIME() functions. 如果需要与时间戳进行转换,可以使用UNIX_TIMESTAMP()FROM_UNIXTIME()函数。

  1. No, don't use comma-seperated values. 不,请勿使用逗号分隔的值。 If you want a user to have the ability to check-out multiple items, you'll need a new table: 如果您希望用户能够签出多个项目,则需要一个新表:

    Tables: Users , Property , Checkout 表格: UsersPropertyCheckout

    The new Checkout table will have the following fields: 新的Checkout表将具有以下字段:

    • id ID
    • person_id 为person_id
    • property_id PROPERTY_ID
    • checkout_date 离开日期
    • checkin_date 登记日期

    This table can have multiple entries for any particular user. 该表可以具有针对任何特定用户的多个条目。 A user may be in there once for a company laptop, and again for a company projector: 用户可能在这里一次是公司笔记本电脑,然后是公司投影仪:

    1 | 1 | 12 | 12 | 23 | 23 | 2009-08-17 | 2009-08-17 | 0000-00-00 0000-00-00
    2 | 2 | 12 | 12 | 28 | 28 | 2009-08-17 | 2009-08-17 | 0000-00-00 0000-00-00

  2. As for checking if an item is reserved, I would as a field in the property table to hold a boolean value: 至于检查某个项目是否被保留,我将作为属性表中的一个字段来保存一个布尔值:

    is_reserved (BOOL) is_reserved (BOOL)

    Finding items that are available is nothing more than checking all items with a BOOL value of false, and no presence in the checkout table coupled with no checkin_date. 查找可用的项目无非就是检查BOOL值为false,且没有在checkout_date中出现在结帐表中的所有项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM