formatting output: grouping results with identical fields
am 10.05.2003 00:03:23 von Molly Gibson
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 ("
class=\"manufacturer\">$newmanufacturer | \n");
}
//print the rest of the stuff
print
("$row->pattern_number | $row->pattern_desc | \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
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Re: formatting output: grouping results with identical fields
am 10.05.2003 00:08:24 von Scott Marlowe
On Fri, 9 May 2003, Molly Gibson wrote:
> 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'm certain there's someone out there doing something stranger than this.
> 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.
What you can do is something like (this is pseudo code) before you start
your while loop:
$current_category =
then in your while loop, check to see if it's changed:
if ($current_category != $new_category){
print $new_category;
$current_category = $new_category;
}
Get the idea? It works a charm for things like this.
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Re: formatting output: grouping results with identical fields
am 13.05.2003 00:31:34 von Molly Gibson
--- "scott.marlowe" wrote:
>
> What you can do is something like (this is pseudo
> code) before you start
> your while loop:
>
> $current_category =
>
> then in your while loop, check to see if it's
> changed:
>
> if ($current_category != $new_category){
> print $new_category;
> $current_category = $new_category;
> }
>
> Get the idea? It works a charm for things like this.
Gotcha...nice to know I was on the right track.
Thanks!
mol
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org