I m stucking with the multiple checkbox that want to store these value into the database.
In my form , that allow the user to select more than one type of languages their like. There are four checkbox
1.)English
2.)France
3.)Mandarin
4.)Others.
In this case, user may select more than one language.So how should i store this value into the database?
my idea is use implode to get the variables into a string, then input that into the database, when you retrieve it you can use explode to get them all back again. Could it be done in this way.
If i need to query from the database which select to show all user that has select only english , how can i make it?
Could anyone give some idea for me.Thank you!
how to store multiple checkbox value into database
Moderator: General Moderators
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
If you just need to store the languages for later use in PHP - you can place the results into an array, serialize the array, and store it on the database in a text field.
Later, grab it from the database, unserialize it - and your original array will be reconstituted for whatever purpose you need it.
Later, grab it from the database, unserialize it - and your original array will be reconstituted for whatever purpose you need it.
you don't want multiple values in one attribute (serialized or not).
probably something like:
table user (user_id, surname, famname, ...)
table userlanguage (user_id, language)
the languages column in userlanguage could be an ENUMeration...
getting all the users that have choosen english goes like
probably something like:
table user (user_id, surname, famname, ...)
table userlanguage (user_id, language)
the languages column in userlanguage could be an ENUMeration...
getting all the users that have choosen english goes like
Code: Select all
SELECT *
FROM user
INNER JOIN userlanguage USING (user_id)
WHERE language='EN';