• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
Sorting as you are doing here is the only way I can think of todo that.
Reply

#3
(06-18-2017, 04: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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.