简体   繁体   English

如何使用数据库中值的复选框,其中类型为coloumn in database(set)codeigniter

[英]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 选择第一个和第二个复选框,我希望这个复选框像这样插入mycoloumn

hobby: (football,study) 爱好:(足球,学习)

how to implement with codeigniter? 如何用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') $_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. $_POST['hobby_1'] || ($this->input->post('hobby_1')看起来像Array(2) [ "football", "dancing" ] ,或者用你检查的任何内容填充。 注意现在这将保存为数组,因此,即使只检查了一个,您仍然必须以阵列形式访问它。

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. 就保存而言,您只需循环输入并构建一个数组并一次插入它,或者您将循环并单独插入它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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