pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Molly Gibson <molly_gibson2002@yahoo.com>
To: pgsql-php@postgresql.org
Subject: formatting output: grouping results with identical fields
Date: Fri, 9 May 2003 15:03:23 -0700 (PDT)
Message-ID: <20030509220323.75714.qmail@web41811.mail.yahoo.com> (raw)

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 ("<TD>$row->pattern_category</TD>
<TD>$row->pattern_manufacturer</TD>
<TD>$row->pattern_number</TD>
<TD>$row->pattern_desc</TD>
</TR>\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 ("<TR><TD>$newcategory</TD></TR>\n");
    }
    if ($row->pattern_manufacturer !=
$newmanufacturer) {
    //we have a new manufacturer sub-heading
		$newmanufacturer = $row->pattern_manufacturer;
		print ("<TR
class=\"manufacturer\"><TD>$newmanufacturer</TD></TR>\n");
	}
	//print the rest of the stuff
	print
("<TD>$row->pattern_number</TD><TD>$row->pattern_desc</TD></TR>\n");
	$i++;
    }

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.

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com




view thread (4+ messages)  latest in thread

Message-ID: <20030509220323.75714.qmail@web41811.mail.yahoo.com>
Permalink:  ../20030509220323.75714.qmail@web41811.mail.yahoo.com/
Also on:    postgresql.org/message-id/20030509220323.75714.qmail@web41811.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: molly_gibson2002@yahoo.com
  Subject: Re: formatting output: grouping results with identical fields
  In-Reply-To: <20030509220323.75714.qmail@web41811.mail.yahoo.com>
  References: <20030509220323.75714.qmail@web41811.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox