Php 如何获取数组中的值以及如何使用codeiniter插入数据库
这里我有一个数组,在这个数组中我又有一个数组名Php 如何获取数组中的值以及如何使用codeiniter插入数据库,php,json,codeigniter,model,Php,Json,Codeigniter,Model,这里我有一个数组,在这个数组中我又有一个数组名studentAbsentId,现在我想在数据库中插入studentAbsentId,就像这里的studentAbsentId2一样,studentAbsentId2不存在,所以我需要插入两行 我的更新代码打印($params) 现在我只想拿学生证,怎么办 预期结果 试试这个,它会有帮助:) 试试这个 $test = array('studentAbsentId' => array('2','3'),'studentAbsentDate' =
studentAbsentId
,现在我想在数据库中插入studentAbsentId
,就像这里的studentAbsentId
2一样,studentAbsentId
2不存在,所以我需要插入两行
我的更新代码打印($params)强>
现在我只想拿学生证,怎么办
预期结果
试试这个,它会有帮助:)
试试这个
$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);
}
$test=array('studentAbsentId'=>array('2','3'),'studentAbsentDate'=>'2017-04-18','reg_date'=>'2017-04-18 04:41:21','created__by'=>'1');
foreach($test['studentAbsentId']作为$tet)
{
$array\u val=array('studentAbsentId'=>$tet,'studentAbsentDate'=>$test['studentAbsentDate'],'created_'=>$test['created_by']);
//echo”“;print_r($array_val);
$this->db->insert('table\u name',$array\u val);
}
那么运行此代码时发生了什么?你看到什么错误了吗?描述并提及您的问题请检查我的更新代码
2
3
<?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);
?>
$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);
}