Jump to content

[SOLVED] users in groups and echo the group on profile


contra10

Recommended Posts

Okay its 4am so i'm about to get some shut eye..

 

but i would have the users table

ie

UserID - Name - email
1    -  Admin - [email protected]
2    -  John - [email protected]
3    -  Sam - [email protected]
4    -  Paul - [email protected]

 

a Groups Table

ie

GroupID - Name
1   - Admins
2   - Users
3   - Noobs

 

then a third table to join them

UserID - GroupID
1   -  1
2   -  3
4   -  3
3   -  2
3   -  3

 

Soo

User = Group

Admin = Admins

John = Users

Sam = Users

Paul = User & Noob

 

then an SQL like

SELECT Users.*, Groups.Name FROM Users 
JOIN UserGroups ON UserGroups.UserID = Users.ID
JOIN Groups ON Groups.id = UserGroups.GroupID
Where Users.ID = $UserID

 

If you only want 1 group per used then just add an extra field in the users table to hold the Group ID

then alter your SQL statment like so

current

SELECT * FROM Users Where ID = $UserID

SELECT Users.*, Groups.Name FROM Users 
JOIN Groups ON Groups.id = Users.GroupID
Where Users.ID = $UserID

assuming the added to users field was called GroupID

 

Hope that helps

 

EDIT: corrections .. but its probably still wrong.. ahh bed is calling

thanks for trying but it doesnt work...and at the same time my users information is stored in a different database and the group inforation is in a different dataase, should i store the group information in a different table in the same database?

 

I'm trying to make it that so a user joins a group and when he/she joins the group name is echoed in their profile and in the group members

Why do you all do it so hard.

 

just add a another field to the user's and call it there_job 1 for user and 2 for admin

 

in the admin part off the website update there_job that easy.

 

see all the user

select * from users where there_job='1'

 

see all the admin

select * from users where there_job='2'

 

see all the user and admin

select * from users where there_job='1'  AND there_job='2'

 

show current users there job

 

select * from users where id='$id'

 

while (job ..............){

 

$your_job=$job['there_job'];

 

}

 

echo" ".your $job['name']." $your_job";

 

 

 

Why do you all do it so hard.

 

just add a another field to the user's and call it there_job 1 for user and 2 for admin

 

in the admin part off the website update there_job that easy.

 

I did also say that :P

 

If you only want 1 group per used then just add an extra field in the users table to hold the Group ID

then alter your SQL statment like so

current

SELECT * FROM Users Where ID = $UserID

SELECT Users.*, Groups.Name FROM Users 
JOIN Groups ON Groups.id = Users.GroupID
Where Users.ID = $UserID

assuming the added to users field was called GroupID

 

Hope that helps

 

EDIT: corrections .. but its probably still wrong.. ahh bed is calling

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.