Jump to content

Usergroup help and questions


xoligy

Recommended Posts

ok ive just added a new table called member_groups and a field called user_levels to my db so here is my questions

 

If i put on the pages where i need to show relevant infomation like the name of the user group (normal, admin etc) i would use this yes?

 

SELECT `member_groups`.*, `userdetails`.`user_level`FROM member_groups, userdetails WHERE `member_groups`.`ID`=/>`userdetails`.`user_levels`

 

(ive put a =/> because i carnt remember which im using at the moment i know one works and the other dont i think its > im using...)

 

Then when i want to rstrict access to a page i would do a query and say if user level is == x display or if user level == x show links is that right? Oh and if i wanted to display the user level name i would just do the query then $row['group']

 

just what to make sure im doint it right im sure i am but  like to check ;)

 

I do have another question (not related to this) i want to ask but i would preffer to discuss via msn, email or pm at some point so if someone is willing to talk let me know :)

Link to comment
https://forums.phpfreaks.com/topic/120728-usergroup-help-and-questions/
Share on other sites

for MySQL.

 

To use Member Groups and have another table for holding all the Auth Levels, i would use an Inner Join with a sort of "Linking Table".

Can get a little complex if you are new to mysql (im a bit rusty tbh).

 

There is an excellent tutorial on phpfreaks explaining JOINS in MySQL.

---

 

Short of that, i will try to explain my method i have recently implemented:

 

You have a Database with 4 tables:

 

User_Groups    |    User_List      |      User_Links      |    User_Auths

---------------------------------------------------------------------

(int)GID              (int)UID                    (int)UID              (int)AID

(varchar)Name    (int)GID                    (int)GID              (varchar)Name

                                                      (int)AID

========================================================

 

So now we see a table for "User Groups", which holds all the groups, as many as you want.

Then we see the table "User List", this holds all your users profiles (name,address etc) along with a unique UID (User ID) and his/her GID (Group ID)

There there is "User Auths" which holds all of the Authority Levels or "Permissions", Each permission has its unique AID (Auth ID).

 

Lastly we notice "User Links", Now this is the special table that links the groups, the users, and the permissions. You can have specific permissions for each user, or Permissions for each Group.

 

 

With this set-up we can get a list of all the permission for a user, All the Users single permissions solely for that user (like Super Admin), and we can also get all the permissions from that users Group (Moderator Perhaps).

 

We can do this using a JOIN query like so:

 

	$sql = "SELECT a.auth
		FROM User_Auths a
			INNER JOIN User_Links l USING (aid)
				WHERE l.gid = '1' OR l.uid = '4';
	";

 

The above assumes "auth" is the name of the field in the "User_Auths" Table (The Permission Name Field That Pages Will Check)

 

Also this assumes you have already retrieved the users "Profile" from the database, so you already have the User ID (uid) and his/her Group ID (gid). Assuming the User ID is 4 and they are in group 1.

...........

 

For a much better explanation please view the phpfreaks tutorial.

 

I hope this helps, (i've probably confused you lol, i confused my self)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.