Page 1 of 2
Help.. Advance User Management .. please..
Posted: Sat Jan 10, 2009 2:24 pm
by anshuverma1989
Hey guys..
This site is great ... hehe .. learnt alot .. but i am stuck with one script i am working on...
Now the thing is in my script.. there can be only three type of membership .. Admin, Sub-Admin and Users.
and admins can make sub-admins.. and sub-admins can make users.
and no one can register it self.. only the higher authority can create there account.. Delete there account.. or change there password..
and yeah like if there are suppose 2 sub-admins .. A and B and there are two users C and D which are made by A and B respectively...
Means .. A made C and B made D.. so now B cannot control C .. not A cannot control D..
is it possible?? if yes.. how??
i am confused..
Re: Help.. Advance User Management .. please..
Posted: Sat Jan 10, 2009 2:35 pm
by jaoudestudios
This is standard, so yes it is possible.
Depending on your database structure the ID of C will belong to A, so A can modify and users that belong to him. When user A creates user C, user C will have a new ID but it will also have a parent ID of user A.
If sub-users can only belong to one parent user (admin) then I would keep it simple and just have an extra column in the user table for parent_id. But if the sub-user can belong to many parent users (admin) then I would have a look up table (roles).
This creates another question, if C creates E, and C belongs to A, does E belong to A? If so then you will need a good reference table.
Re: Help.. Advance User Management .. please..
Posted: Sat Jan 10, 2009 2:41 pm
by anshuverma1989
hmm..
i was thinking of creating 3 tables.. one for admin.. one for sub-admin and one for users..
admin will have admin username and password..
Sub admin will have again username and password field..
and user table will have username, password, subadmin field.. where it will store the sub-admin name ..
will that help??
so when a sub admin log in.. he can see all the users under him .. good idea?? or bad??
Re: Help.. Advance User Management .. please..
Posted: Sat Jan 10, 2009 2:45 pm
by jaoudestudios
Not bad, less flexible though.
If you had 1 user table and a reference/lookup table that contained roles and ownership. More complicated, but it depends on what you plan for the future?
Re: Help.. Advance User Management .. please..
Posted: Sat Jan 10, 2009 2:48 pm
by watson516
You could use a single table.
user_id
user_name
user_password
user_level
user_owner
id, name, and password are all obvious.
level could be 1=user, 5=sub-admin, 9=admin
owner could be the id of the user account that created the account.
Admins would be the only account that doesn't have an owner so just put 0 or -1 for admin.
When you want to query all of the accounts that a user has created, just select all of the accounts where the user_owner equals the currently logged in user's ID.
Re: Help.. Advance User Management .. please..
Posted: Sat Jan 10, 2009 2:51 pm
by anshuverma1989
i think my 3 table plan will be fine with me ..
really dont wanna go so advance.. not really good at PHP ..
thanks for the help.. got this idea from your post only
thanks alot ..
Re: Help.. Advance User Management .. please..
Posted: Sat Jan 10, 2009 3:00 pm
by jaoudestudios
watson516's idea is not bad to keep it simple. If you do go down that route I would not use numbers for levels, as this is not flexible, use names (string :: varchar/char) i.e. admin. Use an enum to store this then it will be just as fast but more readable and flexible. However, this structure can not be expanded, no groups or realms would be possible. Users could not have multiple owners etc... Make sure you do not limit yourself for the future.
Re: Help.. Advance User Management .. please..
Posted: Sat Jan 10, 2009 3:10 pm
by anshuverma1989
hmm ..
i have started working with my 3 tables script.. so hope it works out .. then will be disturbing you guys again .. if i face some problem

hehe .. thanks anyways

Re: Help.. Advance User Management .. please..
Posted: Sun Jan 11, 2009 10:34 am
by anshuverma1989
Hey again ..
I made this script .. everything is working fine ..
now only one thing is left..
i want the users to view and delete the user made by them..
what should be the SQL command?? mainly .. i want when user login he gets a table .. with username field and delete field. If he click delete the user gets deleted.
how should i go about it?
Thanks in advance..

Re: Help.. Advance User Management .. please..
Posted: Sun Jan 11, 2009 10:44 am
by jaoudestudios
Can you post your database schema?
What is your query so far?
Re: Help.. Advance User Management .. please..
Posted: Sun Jan 11, 2009 11:12 am
by anshuverma1989
$head_user = $_SESSION['user'];
$query="select * from subuser where user_name = $head_user";
I want this query .. so that all the sub users come under the head user made them....
please correct this query..
Re: Help.. Advance User Management .. please..
Posted: Sun Jan 11, 2009 11:17 am
by jaoudestudios
I cant correct it without seeing your database schema!
But at first glance you should not use user_name as your key, I would use the ID.
NB: Please post your code with code brackets so it is easier for us to see.
Re: Help.. Advance User Management .. please..
Posted: Sun Jan 11, 2009 11:21 am
by anshuverma1989
this is the database:
CREATE TABLE `users` (
`id` int(20) NOT NULL auto_increment,
`full_name` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_name` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_pwd` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_email` varchar(200) collate latin1_general_ci NOT NULL default '',
`activation_code` int(10) NOT NULL default '0',
`joined` date NOT NULL default '0000-00-00',
`bank` varchar(100) collate latin1_general_ci NOT NULL default '',
`user_activated` int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-------------------------------------------------------------------
CREATE TABLE `subuser` (
`id` int(20) NOT NULL auto_increment,
`full_name` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_name` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_pwd` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_email` varchar(200) collate latin1_general_ci NOT NULL default '',
`activation_code` int(10) NOT NULL default '0',
`joined` date NOT NULL default '0000-00-00',
`head_user` varchar(100) collate latin1_general_ci NOT NULL default '',
`user_activated` int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Code: Select all
<?php
session_start();
if (!isset($_SESSION['user']))
{
header("Location: user_login.php");
}
$head_user = $_SESSION['user'];
include ('dbc.php');
$query="select * from subuser where head_user ='.$head_user' '';
$result=mysql_query($query);
$count=mysql_num_rows($result);
?>
Re: Help.. Advance User Management .. please..
Posted: Sun Jan 11, 2009 11:29 am
by jaoudestudios
I would store head_user as a VARCHAR, but the head_user_id as an INT, it is more efficient, plus if you have 2 john smith in the head_user table then there would be issues!
Your query seems ok, but your php is wrong. Try this...
Code: Select all
$query="select * from subuser where head_user = '".$head_user."'";
Re: Help.. Advance User Management .. please..
Posted: Sun Jan 11, 2009 11:30 am
by jaoudestudios
The other issue with using the name for the key instead of the idea, is if a head_user changes his name, or decides to add his middle name, your structure would fall apart.