从 3 个不同的行显示 3 个不同的列
display 3 different columns from 3 different rows
我有一个 table 结构如下:
离开类型 ID |员工编号 |余额|状态 |
1 | AT0000004 |2 |1 |
2 | AT0000004 |1 |1 |
3 | AT0000004 |3 |1 |
1 | AT0000008 |2 |1 |
2 | AT0000008 |2 |1 |
3 | AT0000008 |2 |1 |
这是 table 架构:
leaveTypeID(PK) | 员工ID(PK) |余额|状态 |
现在我想在我的视图中显示
留下AT000004的余额为:
CL: 2
止损:1
EL: 3
你可以按照这个例子:
您的模特:
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'];
}
}
}
我有一个 table 结构如下:
离开类型 ID |员工编号 |余额|状态 |
1 | AT0000004 |2 |1 |
2 | AT0000004 |1 |1 |
3 | AT0000004 |3 |1 |
1 | AT0000008 |2 |1 |
2 | AT0000008 |2 |1 |
3 | AT0000008 |2 |1 |
这是 table 架构:
leaveTypeID(PK) | 员工ID(PK) |余额|状态 |
现在我想在我的视图中显示 留下AT000004的余额为:
CL: 2 止损:1 EL: 3
你可以按照这个例子:
您的模特:
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'];
}
}
}