简体   繁体   English

座位巴士预订PHP和MySQL

[英]Seats Bus Booking PHP and MySQL

I have another case. 我有另一种情况。
I got the bus with 27 seats 我有27个座位的公共汽车
then, if people pick the seat 4, so nobody can take that seat 4. 那么,如果人们选择座位4,那么没人会坐那个座位4。

my question: 我的问题:

  1. how design database contain 27 seats? 设计数据库如何包含27个席位? I guess using looping until 27 with PHP 我猜想用PHP循环到27
  2. how to show in form, selection form contain the un-booked seat? 表格如何显示,选择表格中包含未预定的座位?
  3. how to prevent if other people take same seat? 如何防止其他人坐同一席位?

thanks. 谢谢。

Database: Have a BusType table with properties that would include the number of seats,cost,etc. 数据库:具有一个BusType表,其属性将包括座位数,费用等。 Have a BusBookedSeats table that will hold a FK relationship to the Bus in question and keep a running total of the number of seats it has remaining and/or booked. 拥有一个BusBookedSeats表,该表将保持与所讨论的巴士的FK关系,并保持其剩余和/或预订的座位总数。

Form: Query the database and take the number of total seats - the number of booked seats. 表格:查询数据库并获取总座位数-已预订的座位数。 Add further validation to show the location of the seat. 添加进一步的验证以显示座位的位置。

Prevention: If the query returns a value greater than 0 (meaning taken in this instance) warn the user that it is taken and inform them to take another seat. 预防措施:如果查询返回的值大于0(在这种情况下表示“接受”),则警告用户已采取该方法,并告知他们改坐其他席位。 Or don't even display the seat to them. 甚至不向他们展示座位。

For your database: 对于您的数据库:

  1. You have a table with busses and available seat numbers 您有一张桌子,上面有公共汽车和可用的座位号
  2. You have a table for reservations 您有一张预订桌
  3. You have a table which has a relation with a reservation on a specific seat on a specific bus 您有一张桌子,它与特定巴士上特定座位的预订有关系

How to show the available seats: 如何显示可用座位:

  1. Do a query for all reserved seats 查询所有预留座位
  2. Draw a picture of the bus and mark all reserved seats 画一张公交车的照片并标记所有保留的座位

How to prevent double reservation: You need some kind of transaction routine but it is hard to tell, when to lock a seat and when to unlock it (eg a user doesn't responds for some time). 如何防止重复预订:您需要某种交易程序,但是很难告诉您何时锁定座位以及何时解锁(例如,用户一段时间未响应)。 Usually you only reserve it at the last step. 通常,您仅在最后一步保留它。 So making sure you have not too many steps or the selection is one of the last steps, you reduce the number of conflicts. 因此,确保您没有太多步骤,或者确保选择是最后一步之一,所以可以减少冲突的数量。

These are indeed only some very basic tips, but the whole problem is too complex to anwser it in short. 这些确实只是一些非常基本的技巧,但是整个问题太复杂了,简而言之。 If you have any specific questions you might want to aks them separately. 如果您有任何特定问题,则可能需要单独询问。

From a DB Perspective, based on what i understand of your requirments, i would suggest something on these lines :- 从数据库角度来看,根据我对您的要求的了解,我会在以下几行中提出一些建议:

  1. Bus Table - containing an entry for each individual bus. 总线表-包含每个单独总线的条目。 Has a column that indicates the seating capacity of this bus. 有一列指示此巴士的座位容量。

  2. User Table - containing an entry for each user who can book a seat on a bus. 用户表-包含每个可以预订公交车座位的用户的条目。

  3. BusUser Table - transaction table containing a record for seat on a bus eg: if bus X has 27 = seating capacity, this table will have 27 records - each with the corresponding seat number associated with it. BusUser Table-交易表,其中包含公共汽车的座位记录,例如:如果公共汽车X的座位数为27 =座位数,则该表将具有27条记录-每个记录都具有与之相关的相应座位号。

From a UI perspective, you display the bus user contents. 从UI角度,您将显示总线用户内容。 When a user selects one of the records on the UI, you associate the user with that record in BusUser table. 当用户选择UI上的记录之一时,会将用户与BusUser表中的该记录相关联。 BusUser - will have a column indicating the user associated with that bus instance. BusUser-将具有一列,指示与该总线实例关联的用户。

Thats the general idea. 多数民众赞成。 Hope that gives some pointers for you to start off on.. 希望能为您提供一些指导。

Make sure you have some sort of a primary key which involves the time of the bus leaves etc along with the unique identifier for each bus (composite primary key). 确保您具有某种主键,其中涉及总线离开的时间等,以及每条总线的唯一标识符(复合主键)。 You can only have the unique identifier of the bus as that will limit each bus to be only ride once :) 您只能拥有公交车的唯一标识符,因为这将限制每辆公交车只能乘坐一次:)

The 27 seats of a bus i think should be handled by your application. 我认为巴士的27个座位应由您的应用程序处理。 Perhaps, insert 27 rows first for each bus and update when someone books a seat. 也许,为每辆公共汽车先插入27行,并在有人预定座位时更新。 This way, you can let the user perhaps select which seat they want as well. 这样,您可以让用户也许也选择他们想要的座位。 (Should be done from your GUI). (应该通过您的GUI完成)。

Of course you should have a status for each seat which you can use to find out whether it is reserved or not. 当然,您应该为每个席位都有一个状态,您可以使用该状态来查找是否已预订。

This is a VERY basic idea and I have not included any diagrams or anything of that sort. 这是一个非常基本的想法,我没有提供任何图表或类似的东西。 I hope I have not spoiled your opportunity to design the database on your own :) 希望我不会破坏您自己设计数据库的机会:)

A database lie In Sane has suggested is a good idea. 在Sane中建议使用数据库谎言是一个好主意。 Stopping duplicate bookings really isn't that difficult - you just need to choose a method. 停止重复预订确实没有那么困难-您只需要选择一种方法即可。

  1. Queue system - When people order you'd append them to the tail of a queue and then have a seperate script to pull people from the head. 排队系统-当人们点餐时,您可以将他们添加到队列的尾部,然后使用单独的脚本将人们从头顶拉开。 You'd then be able to evaluate each order at a steady pace, one by one. 这样您就可以稳定地评估每个订单了。

  2. Database level - If you're going to use MySQL you'd probabaly be better off using a engine like InnoDB which supports transactions (introduction: http://www.databasejournal.com/features/mysql/article.php/3382171/Transactions-in-MySQL.htm ) 数据库级别-如果要使用MySQL,则最好使用支持事务的InnoDB之类的引擎(简介: http : //www.databasejournal.com/features/mysql/article.php/3382171/Transactions -in-MySQL.htm

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

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