Re: print single instance of identical values in multiple rows; multiple instances of unique values ?

From: Date: Sun, 03 Sep 2000 00:18:05 +0000
Subject: Re: print single instance of identical values in multiple rows; multiple instances of unique values ?
Groups: php.db 
Request: Send a blank email to php-db+get-2592@lists.php.net to get a copy of this message
Addressed to: "Greg Glover" <glovergl@bellsouth.net> php-db@lists.php.net ** Reply to note from "Greg Glover" <glovergl@bellsouth.net> Sat, 2 Sep 2000 18:00:22 -0400 > > My problem is this. I am joining two or more mysql tables by ISBN. The > first table is title (a single record per ISBN) and the second is > author (sometimes multiple records per ISBN). As you will see if you > scroll to the bottom of the page, I want to display each title once > and every author once before moving to the next title. However, I have > not been able to find a way to keep the title from displaying multiple > times. > > So, display should be: > > Title1 > Author1 > Author2 > Author3 > Title2 > Author1 > Author2 > Author3 > I whould do it something like this... SELECT Title, Author FROM Titles LEFT JOIN Authors USING( ISBN ) ORDER BY Title, Author # This assumes that a blank title is illegal in the database. $OldTitle = ''; while( list( $Title, $Author ) = mysql_fetch_row( $Result )) { if( $OldTitle != $Title ) { $OldTitle = $Title; echo( "$Title<BR>\n" ); } echo( "$Author<BR>\n" ); } Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.db (#2592) next »