Saving multiple checkbox inq

Hello everybody,

I have a page consisting of check boxs in a category tree format. The user has the option to either check one item or multiple items from the page.
In the event the user selects multiple items how do i go about saving the choices.

  1. do i save the selections into a table-> field (all into a one field)
  2. do i create a separate table and save them as a individual record

whats the best practice.

From a database design perspective, you would save one record per option selected.
Based off what you mention, I’m guessing that you have a user table and an item table (it could be different, but for the sake of this example, let’s just call it “item”).

It seems you have a many to many relationship between the user and the item table (one user can choose more than one category, the same category can belong to more than one user).
If this is the case, then you will need a join table.

Your tables will now consist of the following:

User

  • has an id field

Item

  • has an id field

UserItem

  • has a user_id field.
  • has an item_id field.
  • will have a compound primary key consisting of user_id and item_id.

HTH.