WittyPleb
WittyPleb

Reputation: 553

Codeigniter Multi Select insert values into database

I have a form that uses a multi select so you can select multiple options, how would I make it so that if you pick 2 options, it adds them both into the database as

option1,option2,option3

I'm kind of still new to PHP, I know I will have to put it as an array, I'm just not sure exactly how to do it.

Upvotes: 0

Views: 3023

Answers (2)

Christian Giupponi
Christian Giupponi

Reputation: 7618

If you whant to have an array you can use the php explode function:

$your_options = "option1,option2,option3";
$array = explode(",", $your_option);

now you can access with $array[0], $array[1] and so on...

Upvotes: 1

Muhammad Raheel
Muhammad Raheel

Reputation: 19882

Use varchar field in data base table and then insert it. First take a php variable and assign all values to it should be comma seperated. then use this variable in your query to insert. When you get values by select use explode function there.

Upvotes: 1

Related Questions