Welcome Guest, Not a member yet? Register   Sign In
Get last item in list
#1

Hi, In my database table I would like to be able to get the last row that was created.

Have I got this model function correct. Just unsure of my self not sure if there is another easier way?

PHP Code:
public function getpostinfofordeleteupdate()
{
 
   $query $this->db->order_by('datecreated''desc')
         
     ->limit(1)
         
     ->get($this->db->dbprefix 'posts');

 
   return $query->row_array();

Thanks for your time.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

(This post was last modified: 06-18-2017, 03:28 AM by Martin7483.)

Sorting as you are doing here is the only way I can think of todo that.
Reply
#3

(06-18-2017, 03:27 AM)Martin7483 Wrote: Sorting as you are doing here is the only way I can think of todo that.

Thank you. It works fine just was unsure if any other way using DB stuff in model.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

If you only want the ID of the record you could use a select max to get it
Reply




Theme © iAndrew 2016 - Forum software by © MyBB