pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedformatting output: grouping results with identical fields
4+ messages / 2 participants
[nested] [flat]
* formatting output: grouping results with identical fields
@ 2003-05-09 22:03 Molly Gibson <molly_gibson2002@yahoo.com>
2003-05-09 22:08 ` Re: formatting output: grouping results with identical fields scott.marlowe <scott.marlowe@ihs.com>
0 siblings, 1 reply; 4+ messages in thread
From: Molly Gibson @ 2003-05-09 22:03 UTC (permalink / raw)
To: pgsql-php
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: formatting output: grouping results with identical fields
2003-05-09 22:03 formatting output: grouping results with identical fields Molly Gibson <molly_gibson2002@yahoo.com>
@ 2003-05-09 22:08 ` scott.marlowe <scott.marlowe@ihs.com>
2003-05-12 22:31 ` Re: formatting output: grouping results with identical fields Molly Gibson <molly_gibson2002@yahoo.com>
0 siblings, 1 reply; 4+ messages in thread
From: scott.marlowe @ 2003-05-09 22:08 UTC (permalink / raw)
To: Molly Gibson <molly_gibson2002@yahoo.com>; +Cc: pgsql-php
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 = <category from first row>
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.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: formatting output: grouping results with identical fields
2003-05-09 22:03 formatting output: grouping results with identical fields Molly Gibson <molly_gibson2002@yahoo.com>
2003-05-09 22:08 ` Re: formatting output: grouping results with identical fields scott.marlowe <scott.marlowe@ihs.com>
@ 2003-05-12 22:31 ` Molly Gibson <molly_gibson2002@yahoo.com>
0 siblings, 0 replies; 4+ messages in thread
From: Molly Gibson @ 2003-05-12 22:31 UTC (permalink / raw)
To: pgsql-php
--- "scott.marlowe" <scott.marlowe@ihs.com> wrote:
>
> What you can do is something like (this is pseudo
> code) before you start
> your while loop:
>
> $current_category = <category from first row>
>
> 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* formatting output: grouping results with identical fields
@ 2003-05-09 22:06 Molly Gibson <molly_gibson2002@yahoo.com>
0 siblings, 0 replies; 4+ messages in thread
From: Molly Gibson @ 2003-05-09 22:06 UTC (permalink / raw)
To: pgsql-php
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 ("<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><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++;
}
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
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-05-12 22:31 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-05-09 22:03 formatting output: grouping results with identical fields Molly Gibson <molly_gibson2002@yahoo.com>
2003-05-09 22:08 ` scott.marlowe <scott.marlowe@ihs.com>
2003-05-12 22:31 ` Molly Gibson <molly_gibson2002@yahoo.com>
2003-05-09 22:06 formatting output: grouping results with identical fields Molly Gibson <molly_gibson2002@yahoo.com>
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