Hi to all! Can someone help me about this concept..
I attached here a jpeg file of what I want to become an output.
For the output, i simply want to draw a table that looks like a bus seat layout.

So far, here's what i've got:

<table border="1" cellpadding="20">
        for($i=0; $i<14; $i++){
            echo "<tr>";
            for($x=0; $x<5; $x++){
                echo "<td> </td>";

            echo "</tr>";

I want it to have a number like on the attached jpeg file.
Is this possible with php(For Loop)?

Attachments result.JPG 57.65 KB
4 Years
Discussion Span
Last Post by techxaidz

There are so many ways to play with this. I've used an array to complement the table structure and seeded the array with either text (to display) or 1 (which currently displays a hyphen and if not set increment a counter.

$rows = 14;
$columns = 5;

$ins = array(
    0 => array(
        0 => 'Driver\'s Seat',
        1 => 1,
        2 => 1,
        3 => 1,
        4 => 1
for($i = 1; $i<13; $i++) {
    $ins[$i][2] = 1;

$count = 1;

<table border>
<?php for($row = 0; $row<$rows; $row++): ?>
    <?php for($col = 0; $col<$columns; $col++): ?>
        if(array_key_exists($row,$ins) AND array_key_exists($col,$ins[$row])) {
            if(is_numeric($ins[$row][$col])) {
                echo '-';
            } else {
                echo $ins[$row][$col];
        } else {
            echo $count;
    <?php endfor; ?>
<?php endfor; ?>

You can add css etc. yourself (you may need to move the TD inside the php block to add appropriate classes).


create 2 dimentional array

$ar[0][0]='Driver`s seat';


echo "<table>";
for ($i=0;$i<$totrows;$i++)
    echo "<tr>";
        echo "<td>".$ar[$i][$j]."</td>";
    echo "</tr>";
echo "</table>";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.