简体   繁体   中英

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

i have a function that loads comments from a database. in an other page, I want to get the 3 last rows from a table in my database(so it would show the last 3 comments). that is the function that i have in my model:

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);
        }

That should do it. THere's a function for it in CI. http://ellislab.com/codeigniter/user-guide/database/active_record.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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