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">
    <?php
        for($i=0; $i<14; $i++){
            echo "<tr>";
            for($x=0; $x<5; $x++){
                echo "<td> </td>";
                }

            echo "</tr>";
            }
    ?>
    </table>

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

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.

<?php
$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++): ?>
<tr>
    <?php for($col = 0; $col<$columns; $col++): ?>
    <td>
    <?php 
        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;
            $count++;
        }
    ?>
    </td>
    <?php endfor; ?>
</tr>
<?php endfor; ?>
</table>

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';
$ar[0][1]='';
$ar[0][2]='';
$ar[0][3]='';
$ar[0][4]='';

$ar[1][0]='1';
$ar[1][1]='2';
$ar[1][2]='';
$ar[1][3]='3';
$ar[1][4]='4';

$totrows=count($ar);
echo "<table>";
for ($i=0;$i<$totrows;$i++)
{
    echo "<tr>";
    for($j=0;$j<5;$j++)
        echo "<td>".$ar[$i][$j]."</td>";
    echo "</tr>";
}
echo "</table>";

Thanks paulkd and urtrivedi! It worked!
A Big Big thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.