Not entirely sure what you're trying to do, but would it be sensible to use... $sql="SELECT * FROM Customers ORDER BY zip ASC"; . . and then when you've got the results... if ($myrow = mysql_fetch_array($result)) { $zip=0; $zipcount=0; do { if ($zip!=$myrow[zip]){ if ($zipcount!=0){ echo ("</ol>\n</ul>\n"); }else{ $zipcount=1; } echo ("<ul>\n<li>$zip</li>\n<ol>\n"); } echo ("<li>$myrow[customer]</li>\n"); }while ($myrow = mysql_fetch_array($result)); echo ("</ol>\n</ul>\n"); }
or something like that anyways ;) hope that's useful? cheers, Matt -----Original Message----- From: Rudi Starcevic [mailto:[EMAIL PROTECTED]] Sent: 26 February 2002 11:02 To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Grouped sql output Hi, 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 ? Cheers Rudi. > Thanks Sven, > > I've already got the sql OK. > I have the records set but I want to print it "report like" > So It's needs some thing like a loop with an inner loop Like > > <ol> > > <li>zip > <ul> > <li>customer > <li>customer > </ul> > <li>zip > <ul> > <li>customer > <li>customer > </ul> > > </ol> > > Hope this makes sense. > I'll elaborate more if you think I should. > Cheers > Rudi. > > > Hi friends, > > > > > I've been struggling for a while now so I thought I'd ask. > > What's the easiest way to for to print group sql output. For > > example I need to output customers grouped by zip. Like: zip > > customer a customer b zip customer d customer e zip customer > > c custoemr f customer g > > > > Do I need to build array's and loop through them or > > can I print straight from a record set ( using Postgresql > > or Mysql ) Thanks heaps ! Regards Rudi. > > > > ============================================================= > > Get your personalised email and homepage at www.easymail.info > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > ============================================================= ============================================================= Get your personalised email and homepage at www.easymail.info -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.323 / Virus Database: 180 - Release Date: 08/02/02 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.323 / Virus Database: 180 - Release Date: 08/02/02 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php