Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用codeigniter从表中获取最后3行?_Php_Database_Codeigniter_Get - Fatal编程技术网

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

Php 如何使用codeigniter从表中获取最后3行?,php,database,codeigniter,get,Php,Database,Codeigniter,Get,我有一个从数据库加载注释的函数。 在另一页中, 我想从数据库中的表中获取最后3行(这样它就会显示最后3条注释)。 这就是我在模型中的功能: public function load3Comments(){ $this->db->order_by("c_id", "desc"); $query = $this->db->get('comment'); return $this->get_resul

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

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

应该这样做。它在CI中有一个函数

更具描述性。这个函数的输出是什么?预期产量是多少?这本身并不能告诉我们很多。
public function load3Comments(){
            $this->db->order_by("c_id", "desc");
            $this->db->limit(3);
            $query = $this->db->get('comment');
            return $this->get_results($query);
        }