TimDOES Posted September 19, 2008 Share Posted September 19, 2008 I have multiple products for each model in a table and each product is on its own row. eg. Brand Type Model Brand1 Type1 Model1 Brand1 Type1 Model1 Brand1 Type1 Model1 Brand1 Type2 Model2 Brand1 Type2 Model2 Here is the code I have to loop every row (product) of a certain brand. I am trying to create a heading for each model and then list all the available products under it. Right now the loop labels the model for each row. Please tell me there is an easy way to accomplish this. Any help is much appreciated. Code: $query = "select * from ARL2008 where machineMfctr = '$brand'"; $result = mysql_query($query); if (!$result) { die("Query to show fields from table failed"); } $row = mysql_fetch_array($result) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<h3>".$row['MachineModel']."</h3>"; echo "<div class='threeCol emptyBlox'>".$row['Brand']."</div><a class='blox' style='padding:0px;' href=''><div class='threeCol'>".$row['DESCR1']."</div></a><a class='blox' style='padding:0px;' href=''><div class='threeCol'>$".$row['Retail']."</div></a>"; echo "<div class='clear'></div>"; } Quote Link to comment https://forums.phpfreaks.com/topic/125007-grouping-rows-in-a-loop/ Share on other sites More sharing options...
fenway Posted September 29, 2008 Share Posted September 29, 2008 This doesn't really sound like a DB question... though if that's all in one table, you need to normalize your tables. Quote Link to comment https://forums.phpfreaks.com/topic/125007-grouping-rows-in-a-loop/#findComment-653276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.