如何提取或獲取此數組內的數據?因爲我有一個數據庫錯誤的數據僅僅是一個數組..從數組對象中提取數據
這裏的代碼..
的welcome.php - 控制器
public function test()
{
$this->load->model('Crud');
$username = $this->session->userdata('username');
$data['sc_data'] = $this->select2($username);
$data2['t_data'] = $this->select($data);
$this->load->view('quiz', $data2);
}
private function select($data)
{
$result = $this->Crud->t_select($data);
return $result;
}
private function select2($data)
{
$result = $this->Crud->s_course($data);
return $result;
}
crud.php - 模型
public function t_select($data=array())
{
print_r($data);
$this->db->select('fac_id');
$this->db->where('id', $data);
$query = $this->db->get('tbl_subjects');
return $query->result();
}
public function s_course($data = array())
{
$this->db->select('subject_id');
$this->db->where('stud_id', $data);
$query = $this->db->get('tbl_student_subject');
return $query->result();
}
這是錯誤..
Array([sc_data] => Array([0] => stdClass Object( [subject_id] => 2)[1] => stdClass的對象([subject_id] => 3)))
數據庫出錯
錯誤編號:1054
未知列'陣」在 'where子句'
SELECT fac_id
FROM tbl_subjects
WHERE id
= Array
文件名:C :/wamp/www/sample/application/models/crud.php
行號:42
我應該在哪裏放這段代碼先生?進入控制器?或進入模型? –
您必須將此代碼放在$ data attr。在此之後編輯這一行: –
之後,你的print_t函數將在php中打印你的數組。在數組中,你可以像這樣獲得你的數據:foreach $ data $ dat {echo $ dat [''subject_id「];} –