Reputation: 214
I have these checkboxes on my website and user choices the appropriate one for himself. What is the best way to store it in the database? For example, user selects "Bluetooth", "Camera", "Sunroof" and "Taxi". And I insert their value as an array to the database like "2 3 7 15". How can I later echo them and make them to shows on the page like "Bluetooth Camera Sunroof Taxi"? Or do you have any other ideas? Thanks in advance!
P.s: As my website will be multilanguage, for this reason, I cannot store just string values.
Upvotes: 1
Views: 1571
Reputation: 1301
At the time of store you can make a string of id's by using implode like,
$checkboxes = $this->input->post('check[]');
$check_array = implode(',',$checkboxes);
it makes a string of id's for you like 1,2,3 and so on... and store it in one column.
then at the time of retrieval you can explode that and make an array
explode(',',$check_array);
for display you can match the values with this array and if match found put it selected. I hope it helps. thank you.
Upvotes: 2