代码信号;活动记录类 [英] Codeigniter; Active Records Class
问题描述
您好我的问题是,我只想获取最后一个主题为'最后_...'。一个简单的order_by不会工作看到,因为它会排序论坛,我不想要。代码我到目前为止。我在CodeIgniter内置的活动记录中这样做。
Hello my problems is that I only want to fetch the last topic for the 'last_...'. A simple order_by won't work seeing as it will sort the forums as well, which I don't want. The code I have so far. I am doing this in CodeIgniter's built in Active Records.
return $this->db->select('forums.*,')
->select('Count(topics.id) threads, Count(replies.id) replies')
->select('topics.url last_post_url, topics.name last_post_name, topics.created last_post_date')
->select('users.url user_url, users.name user_name, ranks.name user_rank')
->from('forums')
->join('topics', 'topics.f_id = forums.id', 'left')
->join('replies', 'replies.t_id = topics.id', 'left')
->join('users', 'users.id = topics.a_id', 'left')
->join('ranks', 'users.status = ranks.id','left')
->group_by('forums.id')
->get()
->result();
如果不清楚我要做什么,
我想让它获得论坛,在每一行我想它添加的数字或主题(工作),回复(工作),以及最后一个帖子是谁做的。
In case it isn't clear what I am trying to do; I want it to get the forums, in every row I want it to add the number or topics (working), the number of replies (working), and the who the last post was made by.
原始查询
SELECT `forums`.*, Count(topics.id) threads, Count(replies.id) replies, `users`.`url` user_url, `users`.`name` user_name, `ranks`.`name` user_rank
FROM (`forums`)
LEFT JOIN `topics` ON `topics`.`f_id` = `forums`.`id`
LEFT JOIN `replies` ON `replies`.`t_id` = `topics`.`id`
LEFT JOIN `users` ON `users`.`id` = `topics`.`a_id`
LEFT JOIN `ranks` ON `users`.`status` = `ranks`.`id`
GROUP BY `forums`.`id`
推荐答案
尝试$ row = $ query-> last_row(),如用户指南中所述: http:// codeigniter。 com / user_guide / database / results.html
Have you tried $row = $query->last_row() as on the User Guide: http://codeigniter.com/user_guide/database/results.html
这篇关于代码信号;活动记录类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!