Re: Grouped sql output
| From: | DL Neil | Date: | Tue, 26 Feb 2002 11:13:28 +0000 |
| Subject: | Re: Grouped sql output | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-17302@lists.php.net to get a copy of this message | ||
Hi Rudi,
> I've done this before in coldfusion.
> It's the one thing I'm note sure on how to do the same(ish)
> in PHP - my language of choice.
> If we have the record set the CF code would look like
>
> <ul>
> <cfoutput query="customers> group="zip"> <!--- loop through record
> set --->
> <li>#zip#
> <ol>
> <cfoutput> <!--- inner loop on group by zip --->
> <li>#customer#
> </cfoutput>
> </ol>
> </cfoutput>
> </ul>
>
> So I'm think also to use 2 loops for the same purpose in PHP.
> Can I do this from the record set like above or do I need
> to build array's I wonder ?
No need for arrays - the resultset from the RDBMS effectively is one - SQL-talk says it's a
table (please show
us your SQL query if you have any doubt about this). Make sure the SQL resultset is sorted/grouped
correctly!
You're approach looks right to me - just more CF than PHP-like. How's this?
query RDBMS
check result ok/have at least one row
extract first row
initiate presentation
WHILE not EoD
note zip code
ECHO zip heading
WHILE this row's zip == noted zip AND not EoD
ECHO customer data
end while zip
extract next row from resultset
end while data
terminate presentation
OK?
Regards,
=dn