Your best bet would be to build an associative array to loop over as it would make it alot easier to maintain and edit. You'll need to group your data into a per manufacturer basis and order by manufacturer.
Basic example of an associative array:
Code:
[root array]
|
[mfrid1 array]
|->[product1 array]
|->[product2 array]
[mfrid2 array]
|->[product1 array]
|->[product2 array]
|->[product3 array]