Re: postgresql groups and users

From: Date: Sat, 08 Sep 2001 14:32:39 +0000
Subject: Re: postgresql groups and users
Groups: php.db 
Request: Send a blank email to php-db+get-12264@lists.php.net to get a copy of this message
I finally had the time to check it out, your solution should be really close... to clarify: - one user can be the member of <many> groups - one group can have <many> members I thought that was n on m relation, but oh well :) Anyways: there's no relation groups, but instead a pg_group and pg_user (real database users, no new table users or groups, I wanted to eliminate that one) so in postgresql I do: \d pg_group And the outcome is something like this (it's on another computer, so I could not copy paste) Attribute Type (modifier, but there are none) groname name grousysid integer grolist integer[] (<- those are square brackets in case it's hard to see) Indeces: pg_group_name_index, pg_group_sysid_index When I tried to do a: SELECT * FROM pg_group WHERE "grolist"='1005'; I get this error: ERROR: array_in: Need to specify dimension I think there's my problem, I don't know how to do that... (I do my queries always first in pgsql first, then I parse them to php, to make sure the query will work) When I do a SELECT * FROM pg_group; I get this list: groname grosysid grolist admins 1 {1004} coders 5 {1006, 1005} areas 4 {1006,1005} Now I want the user that logs in with his/her name, and has uid 1005, to get the options that belong to the groups he's member of. So I need to filter something like this: SELECT * FROM pg_group WHERE < his uid is in the grolist>; but how can I manage that? Hope I have been clearer this time... Steve Brett <steve.brett@e- To: Michiel_Lange@actuera.com mis.co.uk> cc: Fax to: 05-09-2001 Subject: Re: postgresql groups and users 15:24 "Michiel Lange" <Michiel_Lange@actuera.com> wrote in message news:OF55D086B0.29937DE4-ONC1256ABE.003FE018@actuera.nl... > for my application in php I connect with a postgresql database. > In this database I have made users and groups, where 1 user can be the > member of many groups (n on m relation) ^^^^^^^^^^^ 1 to many. 1 > n. > That works, but how do I let php find out if a user is a member of a > certain group? do a select . i'm assuming that you post the user id into the groups tables. select * from goups where group_id=7 and user_id=1; if the query returns any results then you have a match. so : $numrows=pg_numrows($query); if ($numrows>0){print"You have a match<br>";} Steve

« previous php.db (#12264) next »