简体   繁体   English

在Grocery Crud中将multiselect字段类型作为数组插入

[英]insert multiselect field type as an array in Grocery Crud

currently i use multiselect field type to selecting from my table, but my concern is the multiselect only inserted in one record, meanwhile what i'm expecting is i can inserted 3 rows when the multiselect reach a 3 selected items. 目前我使用多选字段类型从我的表中进行选择,但我关注的是多选仅插入一个记录,同时我期待的是当多选到达3个选定项时我可以插入3行。

PFB my Code. PFB我的代码。

$car_identification_no = array();
            foreach ($this->db->get_where('drv_user')->result() 
            as $row) {
                $car_identification_no[$row->drv_user_id] = $row->car_identification_no;
            }

->field_type('car_identification_no','multiselect',$car_identification_no)

The result for that record it's like below images 该记录的结果就像下面的图像 在红色

I want to insert that 0,1,3 as an record like below 我想插入0,1,3作为下面的记录

ads_car_aq_id|ads_advertisement_id|car_identification_no|superspring_id|description

9 |2|0|123456
10|2|1|123456
11|2|3|123456

try this : 尝试这个 :

<?php 
  // if youur value is "0,1,3"
  $val="0,1,3";
  $array=explode(",",$val);
  $insert=array();
  foreach($array as $k=>$v)
  { 
    $tmp=array(
      "ads_car_aq_id"=>9,
      "ads_advertisement_id"=>2,
      "car_identification_no"=>$v,
      "superspring_id"=>123456,
      "description"=>""
      );
   array_push($insert,$tmp);
  }
// your table name is "drv_user"
  $this->db->insert_batch('drv_user',$insert);
?>

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

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