如何在 CodeIgniter 的控制器中从数据库中分解数据?
How to Explode data from database in controller of CodeIgniter?
我有一个问题,我想使用 explode 更改数据库中的字符串数据,因为数据在我 post 到数据库之前被分解了。这是我的控制器
public function add_detail()
{
$symptoms_id = implode(',', $this->input->post('symptoms_id'));
$CF_user = implode(',', $this->input->post('CF_user'));
$data = array(
'symptoms_id' => $symptoms_id,
'CF_user' => $CF_user
);
$this->db->insert('consultation_detail', $data);
redirect('User/consultation_result', $data);
}
那个函数是内爆并且它有效,但我也想在控制器中创建一个函数来分解数据。
我就这样试试
public function consultation_result()
{
$data['consultation_detail'] = $this->db->get('consultation_detail')->row();
$CF_user = explode(',', $CF_user);
}
但是它说 undefined $CF_user ,对不起,因为我是新手:(
试试这个
public function consultation_result($data)
{
return explode(',', $data);
}
并像这样使用
$data = array(
'symptoms_id' => consultation_result($this->input->post('symptoms_id')),
'CF_user' => consultation_result($this->input->post('CF_user'))
);
我有一个问题,我想使用 explode 更改数据库中的字符串数据,因为数据在我 post 到数据库之前被分解了。这是我的控制器
public function add_detail()
{
$symptoms_id = implode(',', $this->input->post('symptoms_id'));
$CF_user = implode(',', $this->input->post('CF_user'));
$data = array(
'symptoms_id' => $symptoms_id,
'CF_user' => $CF_user
);
$this->db->insert('consultation_detail', $data);
redirect('User/consultation_result', $data);
}
那个函数是内爆并且它有效,但我也想在控制器中创建一个函数来分解数据。
我就这样试试
public function consultation_result()
{
$data['consultation_detail'] = $this->db->get('consultation_detail')->row();
$CF_user = explode(',', $CF_user);
}
但是它说 undefined $CF_user ,对不起,因为我是新手:(
试试这个
public function consultation_result($data)
{
return explode(',', $data);
}
并像这样使用
$data = array(
'symptoms_id' => consultation_result($this->input->post('symptoms_id')),
'CF_user' => consultation_result($this->input->post('CF_user'))
);