Re: Display question

From: Date: Fri, 01 Aug 2003 09:40:46 +0000
Subject: Re: Display question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-157913@lists.php.net to get a copy of this message
On Fri, Aug 01, 2003 at 03:00:23AM -0500, John T. Beresford wrote: > Hi All, > > I'm having a hard time wrapping my head around this. I have a query > that returns the following (Sorted by col2): > > col1 col2 > ------------- > house1 Com1 > house2 Com1 > house3 Com2 > house4 Com2 > house5 Com3 > house6 Com3 > > > I would like to display it as shown below: > > Com 1 > house1 - Com1 > house2 - Com1 > > Com 2 > house3 - Com2 > house4 - Com2 > > Com 3 > house5 - Com3 > house6 - Com3 > > > I'm having a problem with the header for each 'com' > > Thanks for any pointers, > John i think this is a common task. you can try something like: $last = null; while ( list($col1, $col2) = fetch_next_row() ) { if ($last != $col2) { echo "\n$col2\n"; $last = $col2; } echo "$col1 - $col2\n"; }

« previous php.general (#157913) next »