我在模型中的查询:
public function infoReprob(){
$tid = $this->input->get('tid');
$query = $this->db->select('histprob.tid,histprob.ketprob,histprob.updated_at,otslm.lokasi')->from('histprob')->join('otslm', 'otslm.tid = histprob.tid')->where('histprob.tid', $tid)->get();
return $query->result();
}
以上查询用于在 Ajax View 中生成结果并完美运行。但我还需要计算结果,并且我尝试在 Controller 中使用以下内容:
function index(){
$data['reprobs'] = count($this->m->infoReprob()); // USING COUNT
$this->load->view('front/reprob_view', $data);
}
并在我的 Javascript 中调用变量,如下所示:
<?php echo $reprobs; ?>
但结果是:0,即使实际的 num_rows > 0。
请帮忙解决这个问题..非常感谢
最佳答案
尝试以下代码
function index(){
$data['result'] = $this->m->infoReprob(); // get RESULT
$data['count'] = $this->m->infoReprob(1); // get COUNT
$this->load->view('front/reprob_view', $data);
}
public function infoReprob($count=0){
$tid = $this->input->get('tid');
$query = $this->db->select('histprob.tid,histprob.ketprob,histprob.updated_at,otslm.lokasi')->from('histprob')->join('otslm', 'otslm.tid = histprob.tid')->where('histprob.tid', $tid)->get();
if ($count == 1)
return $query->num_rows();
else
return $query->result_array();
}
关于javascript - 从函数中的查询获取结果并计算 Codeigniter 中的 num_rows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52379361/