【发布时间】:2011-07-31 14:19:57
【问题描述】:
我正在使用 Codeigniter 和活动记录创建一个简单的论坛脚本。
我想使用这个函数来获取所有线程及其各自的回复计数以传回我的控制器。
使用下面的脚本,我只得到数组中返回的第一个线程(及其回复数),而不是我的所有线程。
为什么会这样,如何解决?
function get_threads($id){
$this->load->database();
$this->db->select('title,ID,COUNT(replies.threadID) as replies');
$this->db->from('threads');
$this->db->join('replies', 'threads.ID = replies.threadID');
$query=$this->db->where('forum', $id);
$query=$this->db->get();
$data=$query->result_array();
return $data;
}
【问题讨论】:
-
每个话题都有回复吗?否则你应该使用左连接来获得零回复线程
-
每个线程可以有任意数量的回复。你能澄清一下吗?
标签: codeigniter activerecord loops join