关于来自模型的查询,我已经获得了值并将其存储在变量中,现在我希望它从数据数组中存储以供进一步使用,我该怎么做,我在codeigniter的控制器中。
这是我的控制器完整代码:
public function move_data($queue_id) {
$data = array();
$user = array('user_id' => $this->session->userdata['logged_in']['user_id']);
$getqueuedata = $this->Clinic_model->queue_data($queue_id,$user);
//echo json_encode($getqueuedata);
$data = array (
'queue_id' => $getqueuedata['queue_id'],
'user_id' => $getqueuedata['user_id'],
'clinic_id' => $getqueuedata['clinic_id'],
'order_num' => $getqueuedata['order_num'],
'patient_id' => $getqueuedata['patient_id'],
);
}
当我//echo json_encode($getqueuedata);
取消注释这一行,并注释数组存储时,我会这样:
[{"user_id":"102","clinic_id":"2","order_num":"1","patient_id":"7","status":"2","time_sched":null,"queue_id":"1"}]
在我的完整代码中,我收到错误,我不知道如何从数组中存储我的查询值。
答案 0 :(得分:4)
function' queue_data`返回如下结果:
//$getqueuedata = json_decode($json,true);
Array ( [0] => Array ( [user_id] => 102 [clinic_id] => 2 [order_num] => 1 [patient_id] => 7 [status] => 2 [time_sched] => [queue_id] => 1 ) )
所以你可以这样存储数据:
$data = array (
'queue_id' => $getqueuedata[0]['queue_id'],
'user_id' => $getqueuedata[0]['user_id'],
'clinic_id' => $getqueuedata[0]['clinic_id'],
'order_num' => $getqueuedata[0]['order_num'],
'patient_id' => $getqueuedata[0]['patient_id'],
);
print_r($getqueuedata);
如果函数返回数组对象:
$data = array (
'queue_id' => $getqueuedata[0]->queue_id,
'user_id' => $getqueuedata[0]->user_id,
'clinic_id' => $getqueuedata[0]->clinic_id,
'order_num' => $getqueuedata[0]->order_num,
'patient_id' => $getqueuedata[0]->patient_id,
);