From: Michael Glaesemann <grzm@myrealbox.com>
To: Matthias Weinhold <Matthias.Weinhold@gmx.net>
Cc: pgsql-php@postgresql.org
Subject: Re: array fields in the database and their handling with php4
Date: Mon, 27 Oct 2003 01:10:14 +0900
Message-ID: <E256BE05-07CE-11D8-9192-0005029FC1A7@myrealbox.com> (raw)
In-Reply-To: <20031026160449.7a72effa.Matthias.Weinhold@gmx.net>
Hi Matthias,
On Monday, Oct 27, 2003, at 00:04 Asia/Tokyo, Matthias Weinhold wrote:
> i have a table 'mitarbeiter' in my database, column 'Abteilung' is an
> array{'Abteilung1, Abteilung2'}, because some people work in more than
> one section.
I'm not an expert by any means, but I guess I would recommend using a
different set up for this. I don't know if using an array is the best
way for this situation. I remember reading somewhere that arrays should
really only be used for data that is naturally in an array form. (Plus,
I don't know how to use arrays either! :)
If you can still change the database, I'd recommend making another
table 'abteilung' and drop the 'abteilung' column from 'mitarbeiter'.
The new set up would be this:
table mitarbeiter (name)
table abteilung (name references mitarbeiter(name), abteilung)
Then a query that would return a table with name and abteilung would
look like
SELECT m.name, a.abteilung FROM mitarbeiter as m, abteilung as a where
m.name = 'D. Brenner';
I'm using 'name' as the primary key for mitarbeiter. If you've got a
different primary key (like 'id'), reference that instead of 'name' in
table 'abteilung'.
If you only want one row per name in the query result, I think you
could make a function that would return a list of all abteilung for a
given 'name'. However, you can do this kind of formatting in PHP just
as easily.
When you read the results in via PHP, you can take the name from the
first row to make the first row of your html table. Then take the
'abteilung' from the first (and possibly subsequent) rows of the result
to make the second (and subsequent) rows of the html table.
I'm sorry I can't give you specific help on arrays. Hopefully this will
help.
Michael
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: grzm@myrealbox.com, Matthias.Weinhold@gmx.net
Subject: Re: array fields in the database and their handling with php4
In-Reply-To: <E256BE05-07CE-11D8-9192-0005029FC1A7@myrealbox.com>
References: <20031026160449.7a72effa.Matthias.Weinhold@gmx.net> <E256BE05-07CE-11D8-9192-0005029FC1A7@myrealbox.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