Group info. by Category Without Repetitive Category

r937 forwarded me here from here.

To be brief, I have this:

PLATINUM:
name here

PLATINUM:
name here

PLATINUM:
name here

GOLD:
name here

GOLD:
name here

GOLD:
name here

I would like this:
PLATINUM

  • name here
  • name here
  • name here
  • name here
    GOLD
  • name here
  • name here
  • name here
  • name here

Thanks to r937, I have this query:

mysql_select_db($database_rcofcuser, $rcofcuser);
$query_getCircle = "SELECT ab_medal.medal, president_circle.business, president_circle.employee, president_circle.position FROM ab_medal LEFT OUTER JOIN president_circle ON president_circle.medal_id = ab_medal.medal_id ORDER BY ab_medal.medal_id";
$getCircle = mysql_query($query_getCircle, $rcofcuser) or die(mysql_error());
$row_getCircle = mysql_fetch_assoc($getCircle);
$totalRows_getCircle = mysql_num_rows($getCircle);

With this PHP call:

<?php do { ?>
<h3><?php echo $row_getCircle['medal']; ?></h3>
<p><?php echo $row_getCircle['employee']; ?> and <?php echo $row_getCircle['business']; ?> <?php if (!empty($row_getCircle['position'])) { echo $row_getCircle['position'] . ','; } ?></p>
<?php } while ($row_getCircle = mysql_fetch_assoc($getCircle)); ?>

I’m not sure how to remove the duplication of the ‘$row_getCircle[‘medal’];’. Any suggestions?

Use a conditional that only prints the header when it changes.


$medal = ''
do {
if($medal != $row['medal']) {
    $medal = $row['$medal'];
    echo $medal;
}
// ...