[英]Getting result from a query in a function and count the num_rows in Codeigniter
My query in model : 我在模型中的查询:
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();
}
Above query is used to result and work perfectly in a view in Ajax. 上面的查询用于在Ajax的视图中生成结果并完美地工作。 But I need to count the result also, and I am trying to use the folowong in Controller :
但是我也需要计算结果,并且我试图在Controller中使用folowong:
function index(){
$data['reprobs'] = count($this->m->infoReprob()); // USING COUNT
$this->load->view('front/reprob_view', $data);
}
And call the variable inside my Javascript like : 然后像这样调用我的Javascript中的变量:
<?php echo $reprobs; ?>
But it results : 0, even the actual num_rows is > 0. 但结果是:0,即使实际的num_rows也> 0。
Please help solve this.. Thank you so much 请帮助解决此问题。非常感谢
Try following code 尝试以下代码
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.