Re: Allocated Seating Help
Posted: Thu Dec 05, 2013 11:01 pm
It looks like you have gotten pretty far with managing the array of seats in memory. I don't see any database tables and I think you may want to manage things differently once you get it in the database. For example, I assume that you want to book the theater for different shows that each have multiple dates/times, so you might want database tables like:
[text]Table: shows
id name
1 Waiting for Godot
2 The Dumb Waiter
Table: showtimes
id shows_id date time
1 2 2013-12-10 19:00
2 2 2013-12-10 21:00
Table: tickets
id showtimes_id seat_id users_id
1 2 A01 45
1 2 A02 45
...
125 2 E24 0
125 2 E25 0
Table: users
id first last phone email
45 John Smith 1234567890 john@smith.com[/text]
To find out what tickets are available you just "SELECT * FROM tickets WHERE showtimes_id=2 AND users_id=0". Or read in all the tickets records for a showtime to populate the array in your code above.
It seem like you might want another database table that is a template of all the tickets available for the theater. It would have a record for all seats A1...E25. This data table could also have a priority ranking for all the seats, so for example:
[text]Table: seats
id priority row
A13 1 1
A12 2 1
A14 3 1
A11 4 1
A15 5 1
...
E23 121 5
E02 122 5
E24 123 5
E01 124 5
E25 125 5[/text]
Then you could "SELECT * FROM tickets JOIN seats ON tickets.seat_id=seats.id WHERE tickets.user_id=0 ORDER BY seats.priority". That will give you a prioritized list of available seats. And there is row information to let you know if a block of tickets crosses a row boundary. If it does then keep looking down the list for a free block big enough.
And when you wanted to add a new showtime, you would create a record in the showtimes table and then select all the records in the seats table and insert them into the the tickets table with the new showtimes_id.
[text]Table: shows
id name
1 Waiting for Godot
2 The Dumb Waiter
Table: showtimes
id shows_id date time
1 2 2013-12-10 19:00
2 2 2013-12-10 21:00
Table: tickets
id showtimes_id seat_id users_id
1 2 A01 45
1 2 A02 45
...
125 2 E24 0
125 2 E25 0
Table: users
id first last phone email
45 John Smith 1234567890 john@smith.com[/text]
To find out what tickets are available you just "SELECT * FROM tickets WHERE showtimes_id=2 AND users_id=0". Or read in all the tickets records for a showtime to populate the array in your code above.
It seem like you might want another database table that is a template of all the tickets available for the theater. It would have a record for all seats A1...E25. This data table could also have a priority ranking for all the seats, so for example:
[text]Table: seats
id priority row
A13 1 1
A12 2 1
A14 3 1
A11 4 1
A15 5 1
...
E23 121 5
E02 122 5
E24 123 5
E01 124 5
E25 125 5[/text]
Then you could "SELECT * FROM tickets JOIN seats ON tickets.seat_id=seats.id WHERE tickets.user_id=0 ORDER BY seats.priority". That will give you a prioritized list of available seats. And there is row information to let you know if a block of tickets crosses a row boundary. If it does then keep looking down the list for a free block big enough.
And when you wanted to add a new showtime, you would create a record in the showtimes table and then select all the records in the seats table and insert them into the the tickets table with the new showtimes_id.