View Full Version : increment letters in a loop

04-13-2012, 08:03 PM
hi all,
i am looking for a method to increment letters in a loop.
i am new, but quite confident with a loop with a numerical increment..

I have an array with the following information contained in it. They are seat is's stored in $seatid.

a1,a2,a3, b1,b2,b3,c1,c2,c3 etc until p1,p2,p3

I want to split the array into html rows using a loop, so outputted will be


appreciate the help,


04-13-2012, 08:58 PM
Is that order always the same?
For example, the 6th element of the array is always C1 (arrays start at 0).

If that is the case, the array element doesn't have to be C1 ... because you know $seatid[6] is always C1.

Describe what you're doing ... because I think you might discover a better scheme for doing this.

04-13-2012, 09:38 PM
I am to display a theatre seat layout.
The user of my system will select a checkbox that corresponds to each seat.

This is my plan:


04-13-2012, 10:37 PM
One more question ...
You say you have an array. But how is the data actually stored permanently, MySQL, XML, or a plain text file?

04-13-2012, 11:07 PM
its a mysql table called tbl_seats.
It has 3 fields SeatID, SeatZoneID, SeatDesignationID

04-14-2012, 04:57 AM
This is going to be hard to explain ... but I'll try ...

Maybe you could create a GUI (graphical user interface)
that looks like your map? You could give each
square a CSS class, and use the database to change
the background color and image within. That image
would allow them to click to reserve, or it would not
be a link if the seat was taken ... they could not click
on if it was reserved, unless they were the person logged-in.

In this example, a2 and a3 are reserved.

<div class="row">
<div class="a1"><a href="reserve.php?id=a1"><img src="reserve_me.png"></a></div>
<div class="a2" style="background-color:#ee0000";><img src="reserved.php"></div>
<div class="a3" style="background-color:#ee0000";><img src="reserved.php"></div>
<div class="a4"><a href="reserve.php?id=a4"><img src="reserve_me.png"></a></div>
<div class="a5"><a href="reserve.php?id=a5"><img src="reserve_me.png"></a></div>
<div style="clear:both;"></div>
<div class="row">
<div class="b1"><a href="reserve.php?id=b1"><img src="reserve_me.png"></a></div>
<div class="b2"><a href="reserve.php?id=b2"><img src="reserve_me.png"></a></div>
<div class="b3"><a href="reserve.php?id=b3"><img src="reserve_me.png"></a></div>
<div class="b4"><a href="reserve.php?id=b4"><img src="reserve_me.png"></a></div>
<div class="b5"><a href="reserve.php?id=b5"><img src="reserve_me.png"></a></div>
<div style="clear:both;"></div>

The CSS class as defined in your .css style sheet would look like this:

border:1px solid #000;
background-color: #00ee00;
border:1px solid #000;
background-color: #00ee00;
border:1px solid #000;
background-color: #00ee00;

All of the HTML/CSS would be generated by the PHP.
As you loop through the database, it would either put a link there, or
an image (reserved). You could also affect the background color of the class.
PHP would add inline CSS to affect changes.

In summary, the "form" you are creating is actually a GUI (graphical user interface).

You would also add more columns to each seat, such as customer ID (who reserved it).
And you would also have duplicate MySQL tables, so you would use the same GUI
for different shows (each table is a show). When a show is over, that table is deleted.

And you could use javascripting (JQuery/AJAX) so when the click a seat, it puts
a different image there until they "check out" and pay for them. My example is
a link to a PHP script, but it wouldn't have to be (to eliminate a page refresh).

Well, now I realize how elaborate a GUI would be, but wouldn't it be cool?
A plain HTML form would be difficult to use.

04-16-2012, 02:03 PM

I appreciate the effort that you have put in, in reply to my post!

I like the idea of using php generated css and html, but i am unsure what you mean on a couple of areas:

I take it that the following is an example of code that has been outputted from the server?

1) <div class="a2" style="background-color:#ee0000";><img src="reserved.php"></div>
<div class="a3" style="background-color:#ee0000";><img src="reserved.php"></div>

Should the imgsrc be reserved.png?

2) I dont understand how i can implement a system that deletes tables after their expiry and still be normalized. The following is a link to my schema..

3) I think the GUI idea of yours is the way forward, especially where controlling items on the page i concerned.

Its worth mentioning at this point that the system is going to be designed as a closed circuit system with an operator at a till, rather than an online booking system. Also it is a not for profit task - it is an end of course project Ive been set!



04-16-2012, 05:34 PM
I have an example for you ....

Let's call this the "Seat Engine".

Basically, you will have a table with rows. Each row is a seat.
There will be a seat ID (location, like E4), and the status of the seat (open, reserved),
and the cost of the seat, the person who reserved it, etc.

A PHP script will use a CSS stylesheet to render the graphic seating chart using the database (array).

Here is my working example with demo on picking one seat at a time.
It's just a "proof of concept" on making it work.

See the test page:

Here is the CSS file:

And the icon for the reserve a seat link:

Here is the main file showing how it will builds the graphic display (index.php).
Since I'm not using MySQL in this example, I just use a plain array with only seat ID's.
Scroll around and pick a seat ... you'll see it turn red.

The real script of course would allow picking multiple seats, and reserved seats would not have the link.





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Theater Seating</title>
<link rel="shortcut icon" href="favicon.ico" />
<link href="seats.css" rel="stylesheet" type="text/css" media="all" />

<div id="wrapper">

<div id="largeview">
foreach($seats as $seat){
$box = "<div id=$seat>$seat<br /><a href='index.php?s=$seat'><img src='icon_checkbox.png' alt='Reserve This Seat' title='Reserve This Seat' /></a></div>";

$box = "<div id=$seat style='background-color:#ff0000;'>$seat<br /></div>";

if($seat=="P4" || $seat=="P5" || $seat=="P6"){
$box = "<div id=$seat>$seat<br /></div>";

echo $box;


</div><!-- end wrapper -->

I hope this will get you started on some ideas.

I really think you're making your MySQL tables harder than they need to be.
One table for user profiles (name, email, address, phone, etc).
One table for each show ... that table has a row for each seat.
that's it ... no more tables.

And keep in mind that you can design the seating map to fit an iPad.
Maybe the theater concierge doesn't need to sit behind a desktop PC.


04-17-2012, 10:32 AM
Excellent example!

I had no idea that CSS was so powerful!

In response to your comments about the tables - i agree that the tables are perhaps over complicated. However due to this being a school project, I have taken extra care to ensure that the information is stored in a database that is normalized. In other words, if I have seat information, and show information and customer information all contained in the one table - surely that is not conforming to normalization standards??

Now! To integrate with PHP!!!

Cheers mate!

04-17-2012, 02:16 PM
You're correct about normalization ... probably a good idea to stay on that road.
That won't affect the "seating display engine" though. You can do various JOIN's to
connect relationships with the various tables.

The "seating display" needs to know:
The seat number (or ID).
The status of the seat (open or reserved).
Special configurations (disabled seating, no seating, special reservations, etc).

The "seating display" doesn't care who the person is that has purchased the seat.
Nor does it care what show it is ... but you do have to make sure your query only
selects results for one show when displaying seats. You don't want to show open
seats for a show, when in fact the seat is taken.

To avoid page refreshes on the "seating display", you can also use AJAX (combination
of PHP and javascripting, or JQuery). It's a bit more work to program though.

In the end ... make sure you show us what you have (some sort of demo) ...
I'd be interested to see how it came out.