Re: array fields in the database and their handling with php4

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: Matthias Weinhold <Matthias(dot)Weinhold(at)gmx(dot)net>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: array fields in the database and their handling with php4
Date: 2003-10-26 16:10:14
Message-ID: E256BE05-07CE-11D8-9192-0005029FC1A7@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Michael Glaesemann 2003-10-26 16:30:03 Re: Saving result to file for download
Previous Message Michael Glaesemann 2003-10-26 15:43:49 Saving result to file for download