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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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



[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux