Php 在codeigniter中处理多个复选框阵列

Php 在codeigniter中处理多个复选框阵列,php,mysql,forms,codeigniter,Php,Mysql,Forms,Codeigniter,我将构建一个调查表单生成器name属性是来自数据库的动态属性。所以我不知道任何输入元素的名称。从数据库中,我已经生成了表单及其工作方式,但我在提交多个复选框值并将其存储到数据库中时遇到了问题 我试过: 查看 // $inputtype, $name comes from database. <input type="$inputtype" name="$name"[]> // I can fetch values of all checked option and loop th

我将构建一个调查表单生成器<表单中的code>name属性是来自数据库的动态属性。所以我不知道任何输入元素的名称。从数据库中,我已经生成了表单及其工作方式,但我在提交多个复选框值并将其存储到数据库中时遇到了问题

我试过:

查看

 // $inputtype, $name comes from database.
<input type="$inputtype" name="$name"[]>
 // I can fetch values of all checked option and loop through it and convert it into string using explode and insert into database. Thats not a big deal.
但是,当我尝试以相同的方式插入多个复选框数组时,它在codeigniter库的
mysql/mysql\u driver.php
中抛出错误
array-to-string-conversion
。我怎样才能克服这个问题。请帮忙

更新

$this->input->post()提交表单后获得的数组


但我无法将爱好数组直接存储到数据库。

如果您希望以这种方式存储爱好,则应始终使用带有外键的单独表与用户表关联。表示您的hobbie表包含用户的爱好。i、 e使用用户id,tbl_嗜好.id

如果您想以这种方式存储嗜好,您应该始终使用单独的表,并使用外键与您的用户表关联。表示您的hobbie表包含用户的爱好。i、 e使用用户id,tbl_嗜好.id

尝试使用
$postdata=$this->input->post();打印(postdata)这给了我一个包含所有表单数据和键值对的数组。如果有多个复选框,它会在表单数据数组中生成另一个子数组。然后发布该数组,在这里您将从数据库中获取
复选框的名称attr,因此我无法知道运行时哪个是复选框。所以我不能这样做。将您在
$postdata
变量中获取的数组作为
$postdata=$this->input->Post()发布;打印(postdata)这给了我一个包含所有表单数据和键值对的数组。如果有多个复选框,它会在表单数据数组中生成另一个子数组。然后发布该数组,在这里您将从数据库中获取
复选框的名称attr,因此我无法知道运行时哪个是复选框。所以我不能这样做。在
$postdata
变量中发布您获得的数组
 $this->input->post();   //directly to model.
 array
'first_name' => string 'sushil ' (length=7)
'last_name' => string 'shrestha' (length=8)
'gen' => string 'Male' (length=4)
'hobbies' => 
  array
    0 => string 'gaming' (length=6)
    1 => string 'football' (length=8)
    2 => string 'cricket' (length=7)
'language' => string 'IOS' (length=3)