Forum Moderators: coopster
IMO the best way to do this is no not store them in an array.
I suggest doing all this at the time you make the query, within the while loop. Create a "marker" variable in your while loop for when the category has changed. So "if the category from this row is different than the current category OR the length of this category has exceeded my specified column length, start a new column." Something like that.
This will require you do a count(*) first rather than use the mysql_num_rows, but that count(*) value will become very useful as your products base grows - your normal select will contain a limit clause.
$old_category_id = 0;
$count_category = 0;
foreach( $categories as $category ) {
if($category["category_id"] != $old_category_id) {
$count_category++;
$old_category_id = $category["category_id"];
}}
//echo $count_category;