strtotime()期望参数1为字符串

时间:2018-12-27 04:47:12

标签: php codeigniter-3

我正在使用codeigniter框架在for循环中编写代码,以获得多个插入值。

这是我的代码

 $oldjoindate = $this->input->post('fldWorkHistoryJoiniedDate')  ;
$fldWorkHistoryJoiniedDate = date("Y-m-d", strtotime($oldjoindate));

for ($i=0; $i < count($fldWorkHistoryCompanyName); $i++) {
    $data5[] = array(

        'fldUserID' => $insert_id,
        'fldWorkHistoryCompanyName'=>$fldWorkHistoryCompanyName[$i],
        'fldWorkHistoryJoiniedDate'=>$fldWorkHistoryJoiniedDate[$i],
        //'fldWorkHistoryResignedDate'=>$fldWorkHistoryResignedDate[$i],
        'fldCompanyID' => $fldCompanyID

            );
  $this->db->insert_batch('tblWorkHistory',$data5);
}

1 个答案:

答案 0 :(得分:0)

请问$fldWorkHistoryJoiniedDate是否可以像$ fldWorkHistoryJoiniedDate [0],$ fldWorkHistoryJoiniedDate [1]这样的数组格式进行检查?

$oldjoindate = $this->input->post('fldWorkHistoryJoiniedDate');
// check db data type is Date ?
$fldWorkHistoryJoiniedDate = date("Y-m-d", strtotime($oldjoindate));
// check date is coming proper 
// echo $fldWorkHistoryJoiniedDate;
for ($i=0; $i < count($fldWorkHistoryCompanyName); $i++) {
    $data5[] = array(
        'fldUserID' => $insert_id,
        'fldWorkHistoryCompanyName'=>$fldWorkHistoryCompanyName[$i],
        'fldWorkHistoryJoiniedDate'=>$fldWorkHistoryJoiniedDate[$i],
        //'fldWorkHistoryResignedDate'=>$fldWorkHistoryResignedDate[$i],
        'fldCompanyID' => $fldCompanyID
    );
  $this->db->insert_batch('tblWorkHistory',$data5);
}

//可能不是必需的$fldWorkHistoryJoiniedDate[$i]简单到来的$fldWorkHistoryJoiniedDate