2017-04-18 23 views
0

這裏我有一個陣列,該陣列中的我多了一個數組名studentAbsentId,現在我想插入studentAbsentId數據庫在數據庫中插入,喜歡這裏studentAbsentId 2和studentAbsentId 2是缺席,所以我需要插入兩行如何讓數組的值如何使用codeiniter

我更新的代碼print_r($ params);

Array 
(
    [studentAbsentId] => Array 
     (
      [0] => 2 
      [1] => 3 
     ) 

    [schoolId] => 2 
    [classId] => 1 
    [sectionId] => 1 
    [studentAbsentDate] => 2017-04-18 
    [reg_date] => 2017-04-18 05:20:17 
    [created_by] => 1 
) 

現在我想只拿studentAbsentId,該怎麼辦?

預期結果

2 

3 
+0

到底發生了什麼,當你運行該代碼?你看到任何錯誤?描述並提及您的問題 –

+0

請檢查我的更新代碼 –

回答

1

試試這個它有助於:)

<?php 

$params=array(
     'studentAbsentId' => array 
      (2,3 
      ), 
     'studentAbsentDate' => '2017-04-18', 
     'reg_date' => '2017-04-18 04:41:21', 
     'created_by' => '1', 
    ); 


foreach($params['studentAbsentId'] as $ff) 
{ 
     $atnEntry = array(
     "studentAbsentId" => $ff, 
     "studentAbsentDate" =>$params['studentAbsentDate'], 
     "morning" => "1" 

     ); 

     $this->db->insert("student_absent_list" , $atnEntry); 
}   
     $return = array("status" => "Success"); 
     echo json_encode($return); 

?> 
0

試試這個

$test = array('studentAbsentId' => array('2','3'),'studentAbsentDate' => '2017-04-18','reg_date' => '2017-04-18 04:41:21','created_by' => '1'); 

    foreach($test['studentAbsentId'] AS $tet) 
    { 
     $array_val = array('studentAbsentId' => $tet,'studentAbsentDate' => $test['studentAbsentDate'],'created_by' => $test['created_by']); 

     // echo "<pre>";print_r($array_val); 

     $this->db->insert('table_name',$array_val); 
    }