group or multiple queries?

wxdqz

New Member
I am wanting to pull out a heap of computer products from a database, grouping them by their manufacturer and then have them displayed like this:

SONY
prod 1
prod 2
prod 3

PHILIPS
prod 1
prod 2
prod 3
prod 4

ETc..

To accomplish this I would normally do one query to get each manufacturer and then within that result set I would do another query to get all the products for that manufacturer, like:

$sql=mysql_query(SELECT * FROM products);
while($row=mysql_fetch_row($sql))
{
$manufacturer = $row[4];
print ($manufacturer);

$sql2 = mysql_query("SELECT * FROM products WHERE manufacturer = '$manufacturer'");
while($row2=mysql_fetch_row($sql2))
{
$prod_id = $row[0];
$prod_name = $row[2];
print($prod_name);
etc....
}
}



Is doing this as bad as it looks....should I be using some grouping function to do this instead?

I know I can go GROUP BY manufacturer in the first query but this won't enable me to print out the manufactureres name at the top of the grouped products......will it?

rgds,
Scott d~
 
Back
Top