Thank you John,
That did the trick.
Advertising
Gil
> -----Original Message-----
> From: John W. Holmes [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 16, 2004 9:46 PM
> To: mayo
> Cc: php-db
> Subject: Re: [PHP-DB] sql, grouping problem
>
>
> 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
> > FROM CLASSES c, CLASSCODES cc
> > WHERE c.classId = cc.classId
> > AND ...
> > ORDER BY c.classId, ...
> >
> > <cfoutput query="myQuery" group="classId">
> > #classTitle#
> > #classDescription#<br>...
> > <cfoutput>
> >
> > #classCodeSection#<br>
> > #classDate#<br>
> > #classTime#<br>
> >
> > </cfoutput>
> > </cfoutput>
> >
> > 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: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php