[thelist] Turn pg_query result into lines with three fields [php]

Matt Warden mwarden at gmail.com
Fri Nov 14 15:16:20 CST 2008


On Thu, Nov 13, 2008 at 8:01 AM, Stefan Schwarzer <st.schwarzer at geois.de> wrote:
>        id    y1970    y1971    y1972 ......
>        1       23           25           28
>        2        8             9             5
>        3      83            94          102
>
> into an XML with this format
>
>        id, year, value
>
>
> Seems to me that I can't use the pg_fetch_array, as it doesn't enable
> me to read the column title (the year). There is pg_fieldname for
> that, but then I would have to loop first this one, then the values.

Here you go...

select id, '1970' as yr, yr1970 as val
union all
select id, '1971', yr1971
union all
select id, '1972', yr1972
union all
select ...

Is your table really designed like that, with years as separate columns?

-- 
Matt Warden
Cincinnati, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list