mayo wrote:

cold fusion allows you to group output (see below)

  Select c.classId, c.classTexts, c.classDescription,
  cc.classCodeSection, cc.classDate, cc.classTime,
  cc.classLocation, cc.classInstructor
  WHERE c.classId = cc.classId
  AND ...
  ORDER BY c.classId, ...

<cfoutput query="myQuery" group="classId">


I can't figure out how to do this in php.

You just have to "remember" the value of the classID as you loop through the results, and only show the "header" row when the classID changes.

//Empty classID
$old_classID = '';

//Loop through results
while($row = mysql_fetch_assoc($result))
  //show title and description when
  //classID changes
  if($row['classID'] != $old_classID)
    echo "<tr><td colspan=\"3\">{$row['title']}</td></tr>";
    echo "<tr><td colspan=\"3\">{$row['description']}</td></tr>";
    $old_classID = $row['classID'];

  //show rest of data
  echo "<tr><td>{$row['code']}</td>";
  echo "<td>{$row['section']}</td>";
  echo "<td>{$row['location']}</td></tr>";

The logic is that the title and description rows are only shown when classID changes in the result set. I showed it using MySQL functions, but that can apply to any database/abstraction layer you've got running.

Hope that helps.

---John Holmes...

Amazon Wishlist:

php|architect: The Magazine for PHP Professionals –

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to