In this tutorial, We will explain to you how to get last record from the MySQL table in CodeIgniter. so we will give you a simple example of how to get last row in codeigniter. sometimes, we need to the last record in MySQL using CodeIgniter.
Codeigniter’s provide Active record library, its library used to we can get easily the last record in MySQL and see below example.
if you want to get last record from database In case you used of CodeIgniter function order_by, limit, get and row. it functions help to get a single row of the result.
See below the example of getting the last record from MySQL using CodeIgniter.
public function add() { $this->load->database(); $last_record = $this->db->order_by('id',"desc") ->limit(1) ->get('users') ->row(); echo "<pre>"; print_r($last_record); echo "</pre>"; die; }
Please follow and like us: