database:
id | name
1 | aaa
2 | bbb
3 | ccc
.. | ...
250| zz3
foreach ($datafromdb as $value){
echo $value->name();
}
this show me:
<?php
$data = range(1,16);
$maxColumns = 4;
$maxRows = 4;
?>
<table>
<? for($r = 0; $r < $maxRows; $r++) { ?>
<tr>
<? for($c = 0; $c < $maxColumns; $c++) { ?>
<td><? echo $data[($c*$maxColumns)+$r]?></td>
<? }?>
</tr>
<? } ?>
</table>
You might want to check if the data actually exists before echoing it.
Look, I don't exactly know php but this is what I can think of:
<table>
<tr>
var counter=0;
foreach ($datafromdb as $value){
if (i%12==0) { echo '<td>'; }
echo $value->name()+'<br/>';
if (i%12==0) { echo '</td>'; }
counter++;
}
</tr>
</table>
Hope this helps!
<table>
$index=0;
foreach ($datafromdb as $value)
{
if($index%12==0) echo '<tr>' ;
echo '<td>' . $value->name() . '</td>';
if($index%12==0) echo '</tr>' ;
}
</table>
Daniel Cherrington's code is good, but with only PHP just do:
<?php
$data = range(1,240);
$tab = array();
$max = 12;
for($i=0;$i<sizeof($data);$i++){
$tab[($i % $max)][] = $data[$i];
}
echo "<table border='1'>";
foreach($tab as $line){
echo "<tr>";
foreach($line as $row){
echo "<td>".$row."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
You could try creating tables side by side (float them using css)
$index=0;
foreach ($data as $value)
{
if($index == '12') $index = 0;
if($index == 0) echo '<table style="float:left;">';
echo '<tr>' ;
echo '<td>' . $value . '</td>';
echo '</tr>' ;
if($index==11) echo '</table>' ;
$index ++;
}