Jump to content

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


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 - ME@me.com
2    -  John - john@me.com
3    -  Sam - sam@me.com
4    -  Paul - paul@me.com

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.