繁体   English   中英

如何使用Codeigniter从表中获取最后3行?

[英]how do i get the 3 last rows from a table using codeigniter?

我有一个从数据库加载评论的功能。 在另一页中,我想从数据库中的表中获取最后3行(这样它将显示最后3条评论)。 那就是我模型中的功能:

public function load3Comments(){
            $this->db->order_by("c_id", "desc");
            $query = $this->db->get('comment');
            return $this->get_results($query);
        }
public function load3Comments(){
            $this->db->order_by("c_id", "desc");
            $this->db->limit(3);
            $query = $this->db->get('comment');
            return $this->get_results($query);
        }

那应该做。 这是CI中的功能。 http://ellislab.com/codeigniter/user-guide/database/active_record.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM