Couldn't you just do something like: <? $rows = mysql_query("SELECT * FROM table ORDER BY category, title"); while ($row = mysql_fetch_array($rows)) { if ($row[title] <> $last) print "<b>$row[category]</b><br>\r\n"; print "<li>$row[title]</li><br>\r\n"; $last = $row[title]; } ?> /* Chris Lambert, CTO - [EMAIL PROTECTED] WhiteCrown Networks - More Than White Hats Web Application Security - www.whitecrown.net */ ----- Original Message ----- From: Tim Ward <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; Frédéric Mériot <[EMAIL PROTECTED]>; PHP General List <[EMAIL PROTECTED]> Sent: Wednesday, July 11, 2001 4:00 AM Subject: RE: [PHP] How to fetch a "group by" Query? this is the sort of thing I usually do ... $result = mysql_query($db, "SELECT * FROM filename...") while ($array = mysql_fetch_array($result)) $category[$array["category"]][] = $array["title"]; foreach ($category as $cat=>$title_array) { echo("Category $cat<br>"); foreach ($title_array as $title) echo(" - $title<br>"); } a lot simpler and you don't have to worry about any start and end conditions. This can also be extrapolated to more complex situations, e.g. where $title contains more than just a name you can do sub totals of "title" quantities by category, or whatever. Tim Ward Senior Systems Engineer Please refer to the following disclaimer in respect of this message: http://www.stivesdirect.com/e-mail-disclaimer.html > -----Original Message----- > From: David Robley [mailto:[EMAIL PROTECTED]] > Sent: 11 July 2001 02:17 > To: Frédéric Mériot; PHP General List > Subject: Re: [PHP] How to fetch a "group by" Query? > > > On Tue, 10 Jul 2001 22:10, Frédéric Mériot wrote: > > Hello (again) > > > > I've got a query which extract titles and categories with a > group by on > > the categorie. Is there a simple way to display rows like > this (without > > doing a second query ): > > > > Categorie A > > -titi > > -toto > > -tutu > > > > Categorie B > > -bibi > > -nini > > -fififi > > > > Categorie C > > -titi > > -toto > > -tutu > > > > ... etc > > > > With cold fusion (for those who know) I want to do the same as > > <CFOUTPUT QUERY="myquery" GROUP="categorie"> > > > > Thanks > > Select category, description from table where whatever order > by category, > description > > Then when you display the rows, keep track of the current and > previous > value of $description; if it changes, print the new value. > > -- > David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc > CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA > > Don't stop posting, a good laugh breaks up my day nicely > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] How to fetch a "group by" Query?
Chris Lambert - WhiteCrown Networks Wed, 11 Jul 2001 00:42:48 -0700
- RE: [PHP] How to fetch a "group b... Tim Ward
- [PHP] Downloading Data from Datab... Chris Lambert - WhiteCrown Networks
- [PHP] Downloading Data from Datab... Randy Johnson
- [PHP] Re: Downloading Data fr... David Robley
- RE: [PHP] Re: Downloading... Randy Johnson
- Re: [PHP] Re: Downloa... David Robley
- Re: [PHP] Re: Do... David Robley
- RE: [PHP] Re: Do... Jochen Kaechelin