In my model I have this code:
在我的模型中,我有这个代码:
$sql = "SELECT SUM(options.points) as total
FROM responses
JOIN options ON options.option_id = responses.option_id
JOIN questions ON questions.question_id = responses.question_id
WHERE options.question_id = questions.question_id
AND questions.category_id = " . $category_id . "
AND responses.assessment_id = " . $assessment_id;
$results = $this->db->query($sql);
return $results->row()->total;
In my helper the code is:
在我的帮手中,代码是:
$points = $nin->reportmodel->getTotalPointsAssessmentByCategory(100, $assessment_id);
When I try to display '$points' there's nothing or zero. If I move the code out of the model and put it into the helper, the code works. What am I missing?
当我试图显示'$ points'时,没有任何东西或零。如果我将代码移出模型并将其放入帮助程序,则代码可以正常工作。我错过了什么?
1 个解决方案
#1
0
Try the code below.
请尝试以下代码。
Your_model.php
Your_model.php
class Your_model extends CI_Model {
public function getTotalPointsAssessmentByCategory($category_id, $assessment_id) {
$sql = "SELECT SUM(options.points) as total
FROM responses
JOIN options ON options.option_id = responses.option_id
JOIN questions ON questions.question_id = responses.question_id
WHERE options.question_id = questions.question_id
AND questions.category_id = " . $category_id . "
AND responses.assessment_id = " . $assessment_id;
$query = $this->db->query($sql);
$row = $query->row();
return $row->total;
}
}
On Controller
在控制器上
public function index() {
$this->load->model('your_model');
$points = $this->your_model->getTotalPointsAssessmentByCategory(100, $assessment_id);
}
#1
0
Try the code below.
请尝试以下代码。
Your_model.php
Your_model.php
class Your_model extends CI_Model {
public function getTotalPointsAssessmentByCategory($category_id, $assessment_id) {
$sql = "SELECT SUM(options.points) as total
FROM responses
JOIN options ON options.option_id = responses.option_id
JOIN questions ON questions.question_id = responses.question_id
WHERE options.question_id = questions.question_id
AND questions.category_id = " . $category_id . "
AND responses.assessment_id = " . $assessment_id;
$query = $this->db->query($sql);
$row = $query->row();
return $row->total;
}
}
On Controller
在控制器上
public function index() {
$this->load->model('your_model');
$points = $this->your_model->getTotalPointsAssessmentByCategory(100, $assessment_id);
}