Jump to content

Recommended Posts

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>";

}

Link to comment
https://forums.phpfreaks.com/topic/125007-grouping-rows-in-a-loop/
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.