bradgrafelman
thanks for replying, and I'll try to make some clairifications.
As far as the additional users, although that is highly unlikely an additional user would have more than 1 parent user, I guess it is possible. Example, if i set up an account, and had my wife as an additional user, then my mother-in-law setup and account, it is likely she would add my wife as an additional user. Although i can see this having other issues, like the additional user selecting who their parent user is for the session. that could be determined by a simmple script after the login that sees they have multiple parent users and have them select the one they are working with for that session. So now that I have thought through it with your help, maybe the mapping table would be the best way to go. I guess that could also mean a parent user could be an additional user under a different account. Example I could have my own, then my mom signs up, and she adds me as an additional user. Adds more complexity to the script, but I love a challenge.
here is the proposed users table.
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`FirstName` varchar(35) NOT NULL,
`LastName` varchar(35) NOT NULL,
`Address1` varchar(75) NOT NULL,
`Address2` varchar(75) NULL,
`City` varchar(35) NOT NULL,
`State` varchar(25) NOT NULL,
`Zip` varchar(15) NOT NULL,
`Country` varchar(25) NOT NULL,
`EmailAddress` varchar(75) NOT NULL,
`Password` varchar(75) NOT NULL,
`SignupDate` datetime NOT NULL,
`SignupIP` varchar(15) NOT NULL,
`LoginDate` datetime NOT NULL,
`LoginIP` varchar(15) NOT NULL,
`EmailCode` varchar(25) NOT NULL,
`Confirmed` int(1) NOT NULL,
`Active` int(1) NOT NULL,
`Newsletter` int(1) NOT NULL,
`TmpPassword` int(1) NOT NULL,
`UserLevel` int(5) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `EmailAddress` (`EmailAddress`))
ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `user_mapping` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ParentUserID` int(11) NOT NULL,
`SubUserID` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
I do actually have tables for the state and country, but I have the name put in the user tables, not the id, because I was not sure how to get the state and country without doing a few different select statements.
Is having the name put in okay, or should it be the ID?
CREATE TABLE IF NOT EXISTS `state` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`CountryID` int(5) NOT NULL,
`name` varchar(35) NOT NULL,
`abbr` varchar(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=52 ;
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(35) NOT NULL,
`abbr` varchar(15) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
I haven't ever used joins and stuff, but I am guessing that is what I would use if I put the state and country id's in the user table, maybe something like this?
SELECT users.*, state.name, country.name FROM users, state, country WHERE state.id = users.StateID AND country.id = users.CountryID AND users.id = $user_id
As far as the user levels go, let's see if I can explain it a little better.
I guess it would be kind of like the different levels of users in Word Press. You can have subscribers, authors, editors, admins etc. Each level has different permissions, and the permissions can be used for different levels of users, like the admin would have all the permissions of the other users. So in some cases it could be a 1 to 1, but in other cases, it could be a 1 to many relationship.
One proposed structure with a little data.
CREATE TABLE IF NOT EXISTS `user_levels` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(25) NOT NULL,
`description` varchar(255) NOT NULL,
`price` decimal(5,2) NOT NULL,
`terms` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
INSERT INTO `user_levels` (`id`, `name`, `description`, `price`, `terms`) VALUES
(1, 'free', 'free membership level', '0.00', 'lifetime'),
(2, 'basic monthly', 'Basic level of membership', '4.97', 'monthly'),
(3, 'basic yearly', 'yearly subscription for the basic membership level', '48.00', 'yearly'),
(4, 'advanced', 'advanced level of membership with more options', '7.97', 'monthly');
CREATE TABLE IF NOT EXISTS `user_permissions` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`name` varchar(25) NOT NULL,
`count` int(3) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
INSERT INTO `user_permissions` (`id`, `name`, `count`) VALUES
(1, 'CustomCategories', NULL),
(2, 'AdditionalUserManagement', NULL),
(3, 'AccountsAllowedFree', 3),
(4, 'AccountsAllowedBasic', 8);
CREATE TABLE IF NOT EXISTS `permission_mapping` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`LevelID` int(10) NOT NULL,
`PermissionID` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
INSERT INTO `permission_mapping` (`id`, `LevelID`, `PermissionID`) VALUES
(1, 1, 3),
(2, 2, 2),
(3, 2, 4),
(4, 3, 2),
(5, 3, 4),
(6, 4, 1),
(7, 4, 2);
Maybe I should do a mapping table to map the user id to the permission id? The additional user created by the parent user might not have the same permissions as the parent user, but they can not be more then the parent users permissions. those permissions are to be determined by the parent user. So change the UserLevel in the users table to UserPlan, and that could be NULL by default for additional users, and change the title of the user_level table to user_plans. The user_permissions can stay the same, but the mapping table would have the UserID, and the PermissionsID mapped. So that would be a many to many relationship, cause there is multiple users, and multiple permissions correct?
I really do appreciate the help. Google has been a great friend to, but there is nothing like having stuff looked over by people with experience.
Weedpacket,
yeah, for what I am doing, I problaby do not need any of the address info, unles I want to send them a post card for signing up. Two address lines seem to be the norm, and most of the addresses i have seen on more than 2 lines can be put on 2 fine.
Thanks,
Michael