This problem is perfectly tailored for a modulus solution.
/
The first thing you'll need to do is
bring the data out of mysql.
/
$res = mysql_query("SELECT item FROM table");
while ($data = mysql_fetch_object($res))
$aItem[count($aItem)] = $data->item;
/
Now you just start looping through this
$aItem array you created. I went ahead
and put HTML in the print statements.
*/
print "<Table border=1>";
for ($i = 0; $i < sizeof($aItem); $i++) {
// this will check to see if we should put a line
// between our box of 4 items. (except for the first
// box of course).
if ((($i % 4) == 0) && ($i)) {
print "<Tr><Td colspan=2><hr width=100%></Td></Tr>";
}
if (($i % 2) == 0) {
// print out a <TR> if it's the
// start of the four item box
if ($i == 0)
print "<Tr>\n\t<Td>$aItem[$i]</Td>\n";
else
print "</Tr><Tr>\n\t<Td>$aItem[$i]</Td>\n";
} else { // just print the item out
print "\t<Td>$aItem[$i]</Td>\n";
}
}
print "</Table>";