I'm trying to do something with PHP & MySQL that I just cannot get my head around.
I have a table that takes the following structure (they are two tables but will act as one when they are joined in the SQL query):
id | brand | model
1 | brand1 | model1
2 | brand1 | model2
3 | brand1 | model3
4 | brand2 | modelA
I've been able to get PHP to output the following fine:
brand1 model1
brand1 model2
brand1 model3
brand2 modelA
What I'd really like to be able to do is output it as:
Brand1
Model1
Model2
Model3
Brand2
ModelA
Anyone got any ideas?
This is my current code:
<?php
$result = mysql_query("SELECT cameras.cameraid, cameras.model, brands.brand FROM cameras JOIN brands ON cameras.brandid=brands.brandid WHERE cameras.categoryid='$cat' ORDER BY brands.brand ASC, cameras.level ASC")or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<li><a href='camera.php?id=". $row['cameraid'] . "'>" . $row['brand'] . " " . $row['model'] . "</a></li>";
}
?>