I have the following issue: I’m creating a form to register users on an application and within the different input types there are a couple of checkboxes regarding the language the user speaks. Now since the user might speak more than just one language I was wondering how is that handled in the db? Should I have lang1, lang2, lang3…etc as rows in the ‘users’ table?
Share
That’s not a good idea. The table structure should be something like this:
Then to, for example, get the user’s language choices, this mock query would work:
This means you can update the language names and the name update will happen transparently without you having to worry about editing it in all instances of the user table. This method also allows you to assign as many languages as you want for the user.
EDIT:
Take for example if language is English and Spanish (id 1 and id 2), and the User’s ID is 1. In order to associate the user with the languages:
Now, this assumes that you’re populating your available languages with the values in the
languagetable, with the value of the field beinglanguage.id, and the display of the field beinglanguage.name.