X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A5BEED1B537 for ; Sun, 26 Oct 2003 16:11:18 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 53721-06 for ; Sun, 26 Oct 2003 12:10:47 -0400 (AST) Received: from geos-book.com (geos-book.com [128.121.59.58]) by svr1.postgresql.org (Postfix) with SMTP id BC40FD1B545 for ; Sun, 26 Oct 2003 12:10:46 -0400 (AST) Received: (qmail 39483 invoked by uid 15162); 26 Oct 2003 16:10:40 -0000 Received: from unknown (HELO myrealbox.com) ([218.218.223.125]) (envelope-sender ) by 128.121.59.58 (qmail-ldap-1.03) with SMTP for ; 26 Oct 2003 16:10:40 -0000 Date: Mon, 27 Oct 2003 01:10:14 +0900 Subject: Re: array fields in the database and their handling with php4 Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v552) Cc: pgsql-php@postgresql.org To: Matthias Weinhold From: Michael Glaesemann In-Reply-To: <20031026160449.7a72effa.Matthias.Weinhold@gmx.net> Message-Id: Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.552) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/26 X-Sequence-Number: 2387 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