![]() |
How do I get the last 3 records in a table? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How do I get the last 3 records in a table? (/showthread.php?tid=8824) |
How do I get the last 3 records in a table? - El Forum - 06-02-2008 [eluser]symonel[/eluser] Hi all Any idea how I could get the last 3 records in a table? I'm trying to get the last one with this: Code: $this->db->select_max('product_id') Code: function get_last_products () Code: <?php foreach($last_products->result() as $row): ?> Quote:Message: Undefined property: stdClass::$product_nameWhat I would actually like is something like Code: SELECT TOP 3 FROM products ORDER BY product_id DESC Please help! How do I get the last 3 records in a table? - El Forum - 06-02-2008 [eluser]alekz[/eluser] Try This!! Code: SELECT * FROM products ORDER BY product_id DESC LIMIT 3 Limit gives you the first three rows i hope this can help you.... How do I get the last 3 records in a table? - El Forum - 06-02-2008 [eluser]symonel[/eluser] Yes! Thanks, it worked. |