I am trying to write a logic to display records top to bottom instead of left to right in the table.
Here is my attempt:
<?php $options = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); ?>
<table border="1" colspan="0" cellspan="0">
<?php
$htmldata = "";
$counter = 1;
$rowcount = ceil(count($options) / 3);
for ($i = 0; $i < count($options); $i++) {
echo $counter % 3 ."<br/>";
if ($counter % 3 == 1) {
$htmldata .= "<tr>";
$htmldata .= "<td>".$options[$i]."</td>";
}
if ($counter % 3 == 2) {
$htmldata .= "<td>".$options[$i]."</td>";
}
if ($counter % 3 == 0) {
$htmldata .= "<td>".$options[$i]."</td>";
$htmldata .= "</tr>";
}
$counter++;
}
echo $htmldata;
exit;
?>
</table>
Below is current code output in the table.
But I need the table to output like this.
How can I achieve this?
Can you guys please help me to write this logic?
Also, it currently is showing 10 records, but it may be much more or less, so we need the code to be dynamic.
Any help will be appreciated. Thanks in advance!
NOTE: It must have only 3 columns for any numbers of records and output must be same as displayed in the second picture example for 10 records.



