In this tutorial, I will inform you how to get the last record from the MySQL table in CodeIgniter. we need sometimes the last record in MySQL using CodeIgniter. Codeigniter's provide Active record library, its library used to get 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;
}
Connect With Facebok