I want to ask about output a table in php after looping some data. Previously, I always do loop data to table just horizontally or vertically. But right now, I want to put this looping data to a table horizontally and vertically, so the result could be like this:
data1 | data2 | data3 | data4
data5 | data6 | data7 | data8
and still like that until looping over. So i get 1 data from my table and put it on like that.
My code right now is:
<?php
require ('server.php');
$query = mysql_query("SELECT * FROM ekskul");
if (mysql_num_rows($query) < 1) {
echo "No data.";
} else {
$i = 0;
while ($roweks = mysql_fetch_array($query)) {
echo '<tr class="dark">';
echo "<td>$roweks[nama]</td>";
if ($i % 4 == 0) {
echo "</tr>";
}
$i += 1;
}
}
?>
I don’t get logic about throw the result horizontally, because what I get is always vertically:
data1
data2
data3
...
datan
Use tr opening before the while loop if condition occurs then close the tr and open new tr ..