javascript - 从函数中的查询中获取结果并计算 Codeigniter 中的 num_rows
问题描述
我在模型中的查询:
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 的视图中产生和完美地工作。但我也需要计算结果,我正在尝试在 Controller 中使用 folowong :
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();
}
推荐阅读
- session - 单页应用程序、服务器端会话和页面加载
- c++ - 我如何告诉 em++ 找到 WS2tcpip.h
- react-native - 如何在本机反应中固定元素
- python - 分配前引用的局部变量“responsedata”(使用请求库)
- python - 特定数量的网格点的 matplotlib 流图错误
- c# - 在主类的子类列表值中设置子项
- javascript - FCM 推送通知在本地工作,但不在服务器上
- java - 验证后续模式并将花括号内的任何内容作为字符串获取的 Java 正则表达式将是什么?abc12={p,q}
- ruby-on-rails - rabbitMQ(bunny gem) + sidekiq 在 heroku 中无法用于 ruby 应用程序
- html - 如何限制 CSS Grid 的行大小?