Hi folks,

I have been struggling with this code a while. The code lists artists and curators for exhibits for a specific gallery (GET $id), but I'm having trouble grouping the artists. It works almost fine when there are no curators attached to the exhibit, but as soon as there are curators it mixes the output. Here is an example that shows what I mean: http://norwegianartyearbook.no/the_l...exh.php?id=190
Artists from exhibits with curators are shown in bold.
How can I group the list of artists so the curators will be shown at the end? I did try to make a loop inside the loop but with no luck.

Appriciate any help. Thanks!

Here is the code:
PHP Code:
$result_array = array();
$counter 0;
$id $_GET['id'];

// List of exhibits per gallery
$row 1;
$result mysql_query
    
"SELECT p.id
        , p.title
        , p.info
        , p.galleryid
        , p.start_date
        , p.end_date
        , p.date
        , a.aname
        , a.exhibitid 
        , k.cname
        , k.exhibitid 
        FROM exhibit AS p
        LEFT JOIN artist AS a ON p.id=a.exhibitid
        LEFT JOIN curator AS k ON p.id=k.exhibitid
        WHERE p.galleryid='
$id'
        ORDER BY p.start_date, a.id asc" 
);
$saveTitle '';   
$saveArtist '';   
$saveCurator '';   

// initialize the variables used for checking any changes
while ($list mysql_fetch_array($result)) { 
   
$exhibit '';
   
$artists '';
   
$curators '';
  
$title $list['title'];
  
$info $list['info'];
  
$date $list['date'];
  
$art $list['aname'];
  
$cur $list['cname'];
  
$start $list['start_date'];
  
$end $list['end_date'];
  
$timestamp strtotime($start);
  
$start date("d.m.y",$timestamp);
  
$timestamp strtotime($end);
  
setlocale(LC_TIME"no_NO.ISO_8859-1");
  
$end date("d.m.y",$timestamp);

   
// check if the exhibit name has changed. If it did, display the exhibit info and save the new exhibit name 
   
if ($list['title'] != $saveTitle) {  
     
// display exhibit info
     
$exhibit "<span class='gallinfo'></p>$start-$end </span><span class='galltitle'>".$list['title']." </span><span class='gallinfo'><em>".$list['info']." </em></span><br /><span class='gallinfo'>Artists:</span>";  
     
// save new exhibit name  
     
$saveTitle $list['title'];
   } 
   if (
$list['aname'] != $saveArtist) {  
   
// display all artists  
   
$artists "<span class='gallinfo'>".$list['aname'].",</span>"
     
$saveArtist $list['aname'];
   }
   if (empty(
$list['cname'])) {  
   
$result_array[] = "$exhibit $artists"
   }
   if (
$list['title'] != $saveTitle) {  
     
// display exhibit info
     
$exhibit "<span class='gallinfo'></p>$start-$end </span><span class='title'>".$list['title']." </span><span class='gallinfo'>".$list['info']." </span><br /><span class='gallinfo'>Artists:</span>";  
     
// save new exhibit name  
     
$saveTitle $list['title'];
   } 
   if (
$list['aname'] != $saveArtist) {  
   
// display all artists  
   
$artists "<span class='gallinfo'>".$list['aname'].",</span>"
     
$saveArtist $list['aname'];
   }
   if (
$list['cname'] != $saveCurator) {  
   
// display curators  
   
$curators "<span class='gallinfo'>Curator: ".$list['cname'].",</span>"
     
$saveCurator $list['cname'];
   }
   if (! empty(
$list['cname'])) {  
   
$result_array[] = "$exhibit <b>$artists</b> $curators"
}
}
$result_final "<div id='gallList'>";
foreach(
$result_array as $galleries) {
  if(
$counter == $row) {    
    
$counter 1;
    
$result_final .= "";
  }
  else 
$counter++;
  
$result_final .= "$galleries";
}
if(
$counter) {
  if(
$rows$result_final .= "$row-$counter";
  
$result_final .= "</div>";
}
echo 
$result_final