this is my controller我需要将发布的每个等级除以另一个表中的max_rating,我该怎么做?我现在收到错误
遇到PHP错误严重性:错误
消息:不支持的操作数类型
文件名:controllers / Performance.php
行号:74
我的模特
public function get_max_rating($kpiid){
$this->db->select('max_rating');
$this->db->where_in('id',$kpiid);
$query = $this->db->get('kpi');
return $query->row();
}
我的控制器: ...........
public function evaluate($r_id = 0) {
$this->form_validation->set_rules('rating[]', 'Rating', 'Trim|required');
if ($this->form_validation->run() == FALSE) {
$data = ['errors' => validation_errors()];
$this->session->set_flashdata($data);
$data['emp_review'] = $this->performance_model->get_emp_kpi($r_id);
$data['main_view'] = 'performance/evaluate_emp';
$this->load->view('layouts/main', $data);
} else {
$rating = $this->input->post('rating');
$comment = $this->input->post('comment');
$kpiid = $this->input->post('kpi_id');
$max_rating = $this->performance_model->get_max_rating($kpiid);
$decimal_rating = $rating / $max_rating->max_rating;
$reviewer = $this->session->userdata('user_id');
$ratingd = array();
for ($i = 0; $i < count($kpiid); $i++) {
$ratingd[] = array(
'rating' => $rating[$i],
'comment' => $comment[$i],
'decimal_rating' => $decimal_rating[$i],
'kpi_id' => $kpiid[$i],
'reviewer_id' => $reviewer,
'review_id' => $r_id
);
}
$this->performance_model->add_reviewer_rating($ratingd);
$data = [
'final_comment' => $this->input->post('final_comment')
];
$this->performance_model->insert_final_comment($r_id, $data);
redirect('performance/display');
}
答案 0 :(得分:0)
您可以像这样在decimal_rating
循环内计算for
:
for ($i = 0; $i < count($kpiid); $i++) {
$ratingd[] = array(
'rating' => $rating[$i],
'comment' => $comment[$i],
'decimal_rating' => $rating[$i] / $max_rating->max_rating,
'kpi_id' => $kpiid[$i],
'reviewer_id' => $reviewer,
'review_id' => $r_id
);