Php 在数组Codeigniter中使用SWITCH语句
我试着在我的模型页面的代码中加入开关,但它给了我服务器错误,或者可能是我的语法错误。我想做的是,每当Php 在数组Codeigniter中使用SWITCH语句,php,codeigniter,postgresql,Php,Codeigniter,Postgresql,我试着在我的模型页面的代码中加入开关,但它给了我服务器错误,或者可能是我的语法错误。我想做的是,每当degree的值等于某个特定值时,它就会用相应的名称将其发布或保存到数据库中 以下是我在模型页面中所做的操作: public function changeNow() { $data = array( 'name' => $this->input->post('name'), 'degree' => $this->input-&
degree
的值等于某个特定值时,它就会用相应的名称将其发布或保存到数据库中
以下是我在模型页面中所做的操作:
public function changeNow() {
$data = array(
'name' => $this->input->post('name'),
'degree' => $this->input->post('degree'),
switch($this->input->post('degree')){
case 'POST-BACC':
'high_degree_post_bacc'=>$this->input->post('high_degree_post_bacc');
break;
case 'LLB':
'high_degree_llb'=>$this->input->post('high_degree_llb');
break;
case 'MD':
'high_degree_md'=>$this->input->post('high_degree_md');
break;
}
);
$this->db->update('table_degree', $data);
}
如果删除开关,它将运行。当我把它放进去的时候,它给出了错误
第一次尝试:我照@Marc说的做了
switch($this->input->post('degree')){
case 'POST-BACC':
$data['high_degree_post_bacc']=>$this->input->post('high_degree_post_bacc');
break; } //no luck: still got server error
开关('$this->input->post('degree'){
变量前面有一个”
,缺少一个)
应该是
开关($this->input->post('degree')){
您还尝试在数组中使用switch语句
试着做类似的事情
“BACC后”案例:
$data['high_degree_post_bacc']=$this->input->post('high_degree_post_bacc');
打破
这是完整的答案:试试这个
public function changeNow() {
$data = array(
'name' => $this->input->post('name'),
'degree' => $this->input->post('degree'),
);
switch($this->input->post('degree')){
case 'POST-BACC':
$data['high_degree_post_bacc'] = $this->input->post('high_degree_post_bacc');
break;
case 'LLB':
$data['high_degree_llb'] = $this->input->post('high_degree_llb');
break;
case 'MD':
$data['high_degree_md'] = $this->input->post('high_degree_md');
break;
}
$this->db->update('table_degree', $data);
}
很抱歉,有点小错误,我按照你说的做了(请参见上面的“编辑第一次尝试”),但仍然没有成功。你认为如何?你的错误是什么?你是否将开关从数组分配中取出?服务器错误。我没有加载。我认为语法是这里的错误。