I am trying to insert my array values into html table.
My Table need to have this limits: 5 columns, and the necessary rows, to fit all information.
Something like this:
1 | 2 | 3 | 4 | 5
11 | 22 | 33 | 44 | 55
111 | 222 | 333 | 444 | 555
Any ideas?
<table>
<?php
$i=0;
$queryPiloto = queryPilot();
foreach ( $queryPiloto AS $resultadoQueryPiloto ) { ?>
<?php if ( $i < 5 ) { ?>
<td><input type="checkbox" value="<?php echo $resultadoQueryPiloto['Pilot']; ?>"><?php echo $resultadoQueryPiloto['Pilot'];?></td>
<?php }
else { ?>
<tr>
<td><input type="checkbox" value="<?php echo $resultadoQueryPiloto['Pilot']; ?>"><?php echo $resultadoQueryPiloto['Pilot'];?></td>
</tr>
<?php } ?>
<?php $i++; } ?>
</table>
The data is shown like this:
REFER Piloto4 Piloto2 Piloto1 O99
O96
O95
O94
O90
O86
O80
O79
O77
O76
My Solution:
<?php
$array= array(
1,2,3,4,5,6,7,8,9,0,11,12,13,14,15
);
$verification = 5;
echo '<table border="1">';
echo '<tr>';
for($i = 0; $i < count($array); $i++ )
{
if ( $i == $verification )
echo '<tr>';
if ( $i == $verification )
$verification += 5;
echo '<td>'.$array[$i].'</td>';
if ( $i == $verification )
echo '</tr>';
}
echo '<tr>';
echo '</table>';