X-Original-To: pgsql-php@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 94940475E82 for ; Fri, 9 May 2003 18:07:09 -0400 (EDT) Received: from web41806.mail.yahoo.com (web41806.mail.yahoo.com [66.218.93.140]) by postgresql.org (Postfix) with SMTP id A4424474E4F for ; Fri, 9 May 2003 18:06:33 -0400 (EDT) Message-ID: <20030509220632.99906.qmail@web41806.mail.yahoo.com> Received: from [209.216.163.159] by web41806.mail.yahoo.com via HTTP; Fri, 09 May 2003 15:06:32 PDT Date: Fri, 9 May 2003 15:06:32 -0700 (PDT) From: Molly Gibson Subject: formatting output: grouping results with identical fields To: pgsql-php@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Status: No, hits=-3.1 required=5.0 tests=BAYES_10,FROM_ENDS_IN_NUMS,FROM_HAS_UNDERLINE_NUMS, NO_DNS_FOR_FROM version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/7 X-Sequence-Number: 2012 Sorry if this posts twice, I am having a horrible time with the yahoo interface. Hi list, Textile geek-grrl here--I recently created a postgres database to keep my fabric, pattern, & project inventory. (Do I win a prize for 'weirdest thing for which someone has used postgres'?) I am at the point where I would like to refine the user interface, even though I'm the only one who will ever use it. Currently I have this query: SELECT pattern_category, pattern_manufacturer, pattern_number, pattern_desc FROM patterns ORDER BY pattern_category, pattern_manufacturer, pattern_number; which I have output into a plain ol' table like so (code snippet only, I know it doesn't produce valid html) while ($i < $num) { $row = pg_fetch_object($pattern_info,$i); print ("$row->pattern_category $row->pattern_manufacturer $row->pattern_number $row->pattern_desc \n"); $i++; } This is great for my purposes, but I'd like to clean up the table a bit more and have the category only print once each time it occurs, and the manufacturer only print once in each category. Here is what I came up with: while ($i < $num) { $row = pg_fetch_object($pattern_info,$i); if ($row->pattern_category != $newcategory) { //we have a new category heading $newcategory = $row->pattern_category; print ("$newcategory\n"); } if ($row->pattern_manufacturer != $newmanufacturer) { //we have a new manufacturer sub-heading $newmanufacturer = $row->pattern_manufacturer; print ("$newmanufacturer\n"); } //print the rest of the stuff print ("$row->pattern_number$row->pattern_desc\n"); $i++; } This seems sorta kludgy and a bit limited--like I can't just swap out a different field to sort on. Is there a simpler way to achieve this? I've been poking around php.net and I didn't find anything--but I can't be the only one who wants to do this. Could somebody give me some search tips so I can figure this out? Thanks! mol __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com