Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Allocated Seating Layout Help

$
0
0

Hi,

 

I am building an online ticketing system for a theatre where there is allocated seating.

There are 5 rows, each with 25 seats.

 

E1 to E2

D1 to D25

C1 to C25

B1 to B25

A1 to A25

 

E row is at the front of the cinema.

A is at the back.

 

At the moment I have got as far as to check a database for booked seats, and then have two arrays - one with the seats that are booked, and one with all seats there are in the cinema. One array subtracts duplicates from the other, so that the seats we are left with are seats that have not been booked. I have the list arranged in A-Z order.

 

So at the moment the online ticketing sells from back left (being A1) to the right and then on to the next row and so on.

 

I have two issues, and I really need someone who has done alot of coding to explain the best way to do this.

 

  • I need to have the seating allocation start from the centre of the front row (E) and work outwards. 
    For example if someone books two seats and they are the first booking they may get E12/E15. 
    Then next booking may be for four people and it would get four seats from the middle available maybe E8, E9, E10, E11.
     
  • The next problem is that say if you had all but 2 seats booked in the first row. Seats E24 and E25 are left. 
    Someone books seats online for 3 people, the computer would give them E24, E25 and D12 for example. 
    I need the script to check to make sure the number of tickets booked all have seat numbers starting with the same row number. The maximum tickets that can be booked online is 5 in any one transaction. So I need it to look for up to 5 seats in a row, there cant be a booking with split rows.

 

Again, any help appreciated.

 

Please see below my current code:


	$ArraySeats = array('A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10', 'A11', 'A12', 'A13', 'A14', 'A15', 'A16', 'A17', 'A18', 'A19', 'A20', 'A21', 'A22', 'A23', 'A24', 'A25','B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'B11', 'B12', 'B13', 'B14', 'B15', 'B16', 'B17', 'B18', 'B19', 'B20', 'B21', 'B22', 'B23', 'B24', 'B25','C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13', 'C14', 'C15', 'C16', 'C17', 'C18', 'C19', 'C20', 'C21', 'C22', 'C23', 'C24', 'C25','D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'D11', 'D12', 'D13', 'D14', 'D15', 'D16', 'D17', 'D18', 'D19', 'D20', 'D21', 'D22', 'D23', 'D24', 'D25','E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'E10', 'E11', 'E12', 'E13', 'E14', 'E15', 'E16', 'E17', 'E18', 'E19', 'E20', 'E21', 'E22', 'E23', 'E24', 'E25');

	$result = mysql_query("SELECT seat_number FROM ticket_sales where seat_number <> '' AND void IS NULL AND session_id = $session_id ORDER BY seat_number ASC") 
	or die(mysql_error());  


	// Set initial ArraySeatsTaken as blank so that it can never be null.
	$ArraySeatsTaken[] = '';

	// keeps getting the next row until there are no more to get
	while($row = mysql_fetch_array( $result )) {
	
		$ArraySeatsTaken[] = $row['seat_number'];

	} 

	$ArraySeatsAvail = array_diff($ArraySeats, $ArraySeatsTaken);

	// Set sequential keys for the array.

	$ArraySeatsAvail = array_values($ArraySeatsAvail);

	$seat_number[1] = $ArraySeatsAvail[0];
	$seat_number[2] = $ArraySeatsAvail[1];
	$seat_number[3] = $ArraySeatsAvail[2];
	$seat_number[4] = $ArraySeatsAvail[3];
	$seat_number[5] = $ArraySeatsAvail[4];

Viewing all articles
Browse latest Browse all 13200

Trending Articles