CodeIgniter上的数组到字符串转换

时间:2016-09-02 10:39:59

标签: php codeigniter codeigniter-3

我的问题是想在我的网络应用程序上插入多个复选框。

错误消息

  

数组到字符串转换

请帮忙......

控制器:

public function add_overview_product($type)
{
    if ($this->input->post('submit')) {
        $type        = $type;
        $id_overview = $this->input->post('id_overview');
        $records = array();
        for ($i=0; $i < count($id_overview) ; $i++) {
            $records[] = array(
                'type' => $type,
                'id_overview' => $id_overview[$i]
            );
        }
        $check_idoverview = $this->Biostar->check_idoverview($type,$id_overview);
        if ($check_idoverview > 0) {
            $message = 'Sorry, The Product can not input twice with the same "TYPE" ';
        } else {
            foreach ($records as $key => $value) {
                $datafield = array(
                    'type' => $type,
                    'id_overview' => $id_overview
                );
                $this->Biostar->saveoverviewproduct($datafield);
            }
            $data['type'] = $type;
            $data['content'] = 'biostar/add_specification';
            $this->load->view('dashboard/index', $data);
        }
    }
    $data['diy'] = $diy;
    $data['content'] = 'biostar/add_overview_product';
    $this->load->view('dashboard/index', $data);

}

我的:模特

public function saveoverviewproduct($datafield){
    $sql = $this->db->insert('overview_biostar',$datafield);
    return $sql;
}
public function check_idoverview($type,$id_overview){
    $this->db->select('type');
    $this->db->where('type',$type);
    $this->db->where('id_overview',$id_overview);
    $query = $this->db->get('overview_biostar')->rows();
    return $query;
}

查看:

<form method="post"action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $type; ?>"  >
    <div class="box-body">
        <?php foreach ($audio as $row){ ?>
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="id_overview[]" value="<?php echo $row['title']; ?>"><?php echo $row['title']; ?>
                </label>
            </div>
        <?php } ?>
    </div>

1 个答案:

答案 0 :(得分:0)

$check_idoverview = $this->Biostar->check_idoverview($type,$id_overview);

$id_overview是一个数组。它应该是一个字符串。