Jump to content

seat plan?


davieboy

Recommended Posts

May not be particularly efficient, but here is an example:

 

<?php
$num_seats = 10;

$arr = array('A','B','C','D','E','F');
echo <<<EOF
<h1>Select seats</h1>
<table>
<tr>
	<th> </th>

EOF;
foreach($arr as $arr2)
{
echo <<<EOF
	<th>{$arr2}</th>

EOF;
}
echo <<<EOF
</tr>

EOF;
for($i=1; $i<=$num_seats; $i++)
{
echo <<<EOF
<tr>
	<th>{$i}</th>

EOF;
foreach($arr as $arr2)
{
	echo <<<EOF
	<td><input type="checkbox" name="seat[{$i}][{$arr2}]" /></td>

EOF;
}
echo <<<EOF
</tr>

EOF;
}
echo <<<EOF
</table>
EOF;
?>

 

Generated code:

<h1>Select seats</h1>
<table>
<tr>
	<th> </th>
	<th>A</th>
	<th>B</th>
	<th>C</th>
	<th>D</th>
	<th>E</th>
	<th>F</th>
</tr>
<tr>
	<th>1</th>
	<td><input type="checkbox" name="seat[1][A]" /></td>
	<td><input type="checkbox" name="seat[1][b]" /></td>
	<td><input type="checkbox" name="seat[1][C]" /></td>
	<td><input type="checkbox" name="seat[1][D]" /></td>
	<td><input type="checkbox" name="seat[1][E]" /></td>
	<td><input type="checkbox" name="seat[1][F]" /></td>
</tr>
<tr>
	<th>2</th>
	<td><input type="checkbox" name="seat[2][A]" /></td>
	<td><input type="checkbox" name="seat[2][b]" /></td>
	<td><input type="checkbox" name="seat[2][C]" /></td>
	<td><input type="checkbox" name="seat[2][D]" /></td>
	<td><input type="checkbox" name="seat[2][E]" /></td>
	<td><input type="checkbox" name="seat[2][F]" /></td>
</tr>
<tr>
	<th>3</th>
	<td><input type="checkbox" name="seat[3][A]" /></td>
	<td><input type="checkbox" name="seat[3][b]" /></td>
	<td><input type="checkbox" name="seat[3][C]" /></td>
	<td><input type="checkbox" name="seat[3][D]" /></td>
	<td><input type="checkbox" name="seat[3][E]" /></td>
	<td><input type="checkbox" name="seat[3][F]" /></td>
</tr>
<tr>
	<th>4</th>
	<td><input type="checkbox" name="seat[4][A]" /></td>
	<td><input type="checkbox" name="seat[4][b]" /></td>
	<td><input type="checkbox" name="seat[4][C]" /></td>
	<td><input type="checkbox" name="seat[4][D]" /></td>
	<td><input type="checkbox" name="seat[4][E]" /></td>
	<td><input type="checkbox" name="seat[4][F]" /></td>
</tr>
<tr>
	<th>5</th>
	<td><input type="checkbox" name="seat[5][A]" /></td>
	<td><input type="checkbox" name="seat[5][b]" /></td>
	<td><input type="checkbox" name="seat[5][C]" /></td>
	<td><input type="checkbox" name="seat[5][D]" /></td>
	<td><input type="checkbox" name="seat[5][E]" /></td>
	<td><input type="checkbox" name="seat[5][F]" /></td>
</tr>
<tr>
	<th>6</th>
	<td><input type="checkbox" name="seat[6][A]" /></td>
	<td><input type="checkbox" name="seat[6][b]" /></td>
	<td><input type="checkbox" name="seat[6][C]" /></td>
	<td><input type="checkbox" name="seat[6][D]" /></td>
	<td><input type="checkbox" name="seat[6][E]" /></td>
	<td><input type="checkbox" name="seat[6][F]" /></td>
</tr>
<tr>
	<th>7</th>
	<td><input type="checkbox" name="seat[7][A]" /></td>
	<td><input type="checkbox" name="seat[7][b]" /></td>
	<td><input type="checkbox" name="seat[7][C]" /></td>
	<td><input type="checkbox" name="seat[7][D]" /></td>
	<td><input type="checkbox" name="seat[7][E]" /></td>
	<td><input type="checkbox" name="seat[7][F]" /></td>
</tr>
<tr>
	<th>8</th>
	<td><input type="checkbox" name="seat[8][A]" /></td>
	<td><input type="checkbox" name="seat[8][b]" /></td>
	<td><input type="checkbox" name="seat[8][C]" /></td>
	<td><input type="checkbox" name="seat[8][D]" /></td>
	<td><input type="checkbox" name="seat[8][E]" /></td>
	<td><input type="checkbox" name="seat[8][F]" /></td>
</tr>
<tr>
	<th>9</th>
	<td><input type="checkbox" name="seat[9][A]" /></td>
	<td><input type="checkbox" name="seat[9][b]" /></td>
	<td><input type="checkbox" name="seat[9][C]" /></td>
	<td><input type="checkbox" name="seat[9][D]" /></td>
	<td><input type="checkbox" name="seat[9][E]" /></td>
	<td><input type="checkbox" name="seat[9][F]" /></td>
</tr>
<tr>
	<th>10</th>
	<td><input type="checkbox" name="seat[10][A]" /></td>
	<td><input type="checkbox" name="seat[10][b]" /></td>
	<td><input type="checkbox" name="seat[10][C]" /></td>
	<td><input type="checkbox" name="seat[10][D]" /></td>
	<td><input type="checkbox" name="seat[10][E]" /></td>
	<td><input type="checkbox" name="seat[10][F]" /></td>
</tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/45156-seat-plan/#findComment-219280
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.