PHP Code:
$col = 0;
$titlerow = array();
$valuerow = array();
echo '<table border="1">';
foreach ($displayDevice as $key1=> $value) {
if ($value > 0) { // add new values to the two rows
$col++;
$titlerow[] = $key1;
$valuerow[] = $value;
if ($col > 4) { // when there are five columns then display the two rows
echo "<tr><td>" . implode("</td><td>", $titlerow) . "</td></tr>";
echo "<tr><td>" . implode("</td><td>", $valuerow) . "</td></tr>";
// reset variables
$col = 0;
$titlerow = '';
$valuerow = '';
}
}
}
if ($col > 0) { // display the remaining values (if any)
echo "<tr><td>" . implode("</td><td>", $titlerow) . "</td></tr>";
echo "<tr><td>" . implode("</td><td>", $valuerow) . "</td></tr>";
}
echo "</table>";
edit: actually, if you can have a number of values that isn't a multiple of 5 (12 for example), then you'd want to add three empty td's to the last rows.
Bookmarks