1
votes

In an application I'm working on there is a select menu which has options such as Pending, Active, Inactive. I'd like to allow users to create their own custom options to include in these menus. They should be allowed to add edit and delete their own custom options but not the system defaults. What would a good normalized mysql schema look like for this?

1

1 Answers

1
votes

Have a look at this post and especially at this resource: http://www.billsternberger.net/jquery/dynamically-add-dropdownlist-option-using-jquery/

It's very simple and does what you want (except for deleting, but that shouldn't be hard to implement :))

Concerning the table structure, I's suggest to have a table for the select entries that could have following fields:

select_id (int 11), value (varchar 255), added_by_user (int 1)

where added_by_user does not specify the user but tells if it was added by a user. And in the users table, you could add the field select_id as a foreign key. Now you can tell, if an entry was added by a user, and if so, by which user.

That's pretty basic, but as I said, it's just one way of doing it (and the way I do it :)), and you get the idea.

//EDIT:

If you want a user to be able to have more than one entry, the entries table should, of course, contain the users_id as a foreign key (and not the other way around as it is in the case above):

select_id (int 11), value (varchar 255), added_by_user (int 1), user_id (int 11)

Depending on how the user_ids are handled (e.g. user with ID = 0 is admin or something) the added_by_user field might be obsolete here.