我的表格如下:
1 | AT0000004 | 2 | 1 |
2 | AT0000004 | 1 | 1 |
3 | AT0000004 | 3 | 1 |
1 | AT0000008 | 2 | 1 |
2 | AT0000008 | 2 | 1 |
3 | AT0000008 | 2 | 1 |
这是表架构:
leaveTypeID (PK)| employeeID (PK)|平衡|状态|
现在我想在我的视图中显示 将AT000004的余额保留为:
CL:2 SL:1 EL:3
答案 0 :(得分:1)
您可以按照以下示例:
您的型号:
public function modelFucntion(){
$this->db->select('leaveTypeID,balance');
$this->db->from('table');
$this->db->where('employeeID','AT0000004');
$query = $this->db->get();
return $query->result_array();
}
您的控制器:
$data['result'] = $this->model_yourModel->modelFucntion(); // calling function.
$this->load->view('viewHTML', $data); // load view
您的观点:
if(count($result) > 0){
foreach ($result as $key => $value) {
if($value['leaveTypeID'] == 1){
echo "CL : ".$value['balance'];
}
if($value['leaveTypeID'] == 2){
echo "SL : ".$value['balance'];
}
if($value['leaveTypeID'] == 3){
echo "EL : ".$value['balance'];
}
}
}