Re: Database/Table Design for Global Country Statistics

From: Stefan Schwarzer <stefan(dot)schwarzer(at)grid(dot)unep(dot)ch>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Database/Table Design for Global Country Statistics
Date: 2007-09-12 12:32:14
Message-ID: 15C8634F-43F6-4CA4-8202-61B64C01A401@grid.unep.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Many, many thanks for that and the other advices from everybody.
You're great!

As I am neither expert in PHP, nor in Postgres, MySQL, Javascript,
HTML etc. etc., all I do in the forums is asking questions; and not
"adding value" by helping others (due to my limited knowledge). All I
can do is offer you a moment of relaxation by looking at some really
nice nature/landscape photos @ http://photoblog.la-famille-schwarzer.de

Cheers,

Stef

On Sep 12, 2007, at 11:45 AM, Richard Huxton wrote:

> Stefan Schwarzer wrote:
>> Thanks for the feedback and the suggestions.
>> A problem I have now when using the new design is the following:
>> As a result from my PostGres query I get something like this:
>> year | value | name
>> ---------------------------------------
>> 2001 | 123 | Afghanistan
>> 2002 | 125 | Afghanistan
>> 2003 | 128 | Afghanistan
> [etc]
>> The way it is displayed on the web (in table form) is the "usual"
>> way:
>> name 2001 2002 2003 2004 2005
>> -----------------------------------------------------------------
>> Afghanistan ....
>> Albania ....
>> Is there any "simple", elegant solution for PHP, so that it does
>> this transformation? I can't imagine that I would have to write a
>> couple of IFs to achieve that. But I have no other idea. Or is it
>> a question of writing a more elegant SQL query?
>
> $curr_yr = -1
> $cols = array();
> while (<fetch rows>) {
> if ($row['year'] != $curr_yr) {
> if (sizeof($cols) > 0) { display_table_row($cols); }
> $cols = array();
> $curr_year = $row['year'];
> }
> $cols[] = $row['value'];
> }
> // handle possible last row of table
> if (sizeof($cols) > 0) { display_table_row($cols); }
>
>
> Make sure your query is ordered properly and you don't have gaps in
> your years.
>
> --
> Richard Huxton
> Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-09-12 12:33:24 Re: Database/Table Design for Global Country Statistics
Previous Message Asko Oja 2007-09-12 12:32:04 Re: Sthange things happen: SkyTools pgbouncer is NOT a balancer