douju8113 2017-04-18 11:21
浏览 53
已采纳

如何获取数组中的值以及如何使用codeigniter在数据库中插入

Here i have one array, in this array i have one more array name studentAbsentId, now i want insert the studentAbsentId in database, like here studentAbsentId 2 and studentAbsentId 2 is absent so i need to insert the two rows

My updated code 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
)

Now i want to take only studentAbsentId,how can do?

expected results

2

3
  • 写回答

2条回答 默认 最新

  • dtwvr26066 2017-04-18 12:03
    关注

    Try this it helps :)

    <?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);  
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?