简体   繁体   中英

how to using check box with value from database where type coloumn in database (set) codeigniter

I have checkbox example hobby first checkbox : footbal second checkbox : study third checkbox :dance .......

Ichoose first and second checkbox and I want this checkbox inserting mycoloumn like this

hobby: (football,study)

how to implement with codeigniter?

I think you're looking for something like this. When you add the [] to the name of an input with the same name, it will be saved as an array in your post:

<div class="input-group">
    <input type="checkbox" name="hobby_1[]" value="football" />
    <input type="checkbox" name="hobby_1[]" value="dancing" />
</div>

So your $_POST['hobby_1'] || ($this->input->post('hobby_1') $_POST['hobby_1'] || ($this->input->post('hobby_1') would look like Array(2) [ "football", "dancing" ] , or be filled with whatever you have checked. NOTE this will now always be saved as an array, so even if there is only one checked, you will still have to access this as an array.

As far as saving, you would just loop through the inputs and either build an array and insert it at one time, or you would loop through and insert them individually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM