Simple solution:
(Assuming mysql)
// in category any category
$mysql_link = mysql_connect("localhost","","");
$db = mysql_select_db("grocerydb",$mysql_link);
// dummy SQL to obtain total_num_rows below
$result = mysql_query("SELECT * FROM grocerytable WHERE category = $category");
$total_num_rows = mysql_affected_rows
$counter = 0;
($mysql_link);
<table><tr>
this should be done databasedriven as well
$foodstuff_array[] = "Beef";
$foodstuff_array[] = "Deli Meat";
more subsections into the array
for ($n=0;$n<count($foodstuff_array);$n++) {
// new db connection
$result = mysql_query("SELECT * FROM grocerytable WHERE category = $category AND foodstuff = $foodstuff_array[$n]")
// then the while loop
while($fetch = mysql_fetch_array($result)) {
if ($counter == (int($total_num_rows/4)) {
echo "</tr><tr>";
} else {
SHOW THE CHECKBOXES SIMPLY
}
$counter++;
}
Messy code - probably not working either - but it should give you some hints on how to solve it.
1) Find out the total amount of rows in the category
2) Set an array with each subsection of food
3) loop through each subsection
4) always keep a $counter
5) before you show the checkbox, test and see if 1/4 have been countered in the counter
6) be careful with loops (slows down)
7) good luck