Answer the question
In order to leave comments, you need to log in
Automatic addition to the database?
There are tables:
options -> id | option_name ,
users -> id | name | surname ,
users_options -> id | option_id | user_id | option_status ;
As when adding data only to the user's table, automatically create options for it with a default value.
To somehow turn out like this:
------- users_options -------
id | option_id | user_id | option_status
1 1 1 off
2 2 1 on
3 3 1 off
Answer the question
In order to leave comments, you need to log in
And if your default options change from some point? To store default options, I would use a table like
default_new_user_options -> id | option_id | option_status
And when creating a user, would add options from it to users_options using the trigger
DELIMITER $$
CREATE TRIGGER add_new_user
AFTER INSERT
ON users FOR EACH ROW
BEGIN
insert into users_options(option_id, user_id, option_status)
select option_id, new.id, option_status from default_new_user_options ;
END$$
DELIMITER ;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question