How to get last record from MySQL table in Codeigniter?By Hardik Savani | March 9, 2017 | | 1533 Viewer | Category : MySql Codeigniter
Share this post:
In this post we are going to learn how to get last single record from MySQl database table using Codeigniter database library.
We sometime require to get only single row result in our Codeigniter application. In this post you can see how to get whole last record using Codeigniter db query. Few day ago i posted "How to get last inserted id in Codeigniter?", in that post we can simply get last inserted id from Codeigniter db query.
In this database query i used order_by(), limit(), get() and row(). order_by() will help to make order by id as descending, limit() will help to get only single result, get() will help to select specific table and row() will help to get single row of result.
So, let's see bellow Codeigniter database query for getting last record:
$last = $this->db->order_by('id',"desc")
You can easily use above Codeigniter database query for fetch single record. So you can simple use as like above normal example.
I hope it can help you...
- How to get last inserted id in Codeigniter?
- Codeigniter 3 - CRUD(Create, Read, Update and Delete) using JQuery Ajax, Bootstrap, Models and MySQL
- How to get last record of database table in Laravel?
- How to get last executed query in Larave 5?
- Codeigniter 3 and AngularJS CRUD with Search and Pagination Example.
- How to retrieve number of twitter followers count without authentication or api ?
- How to get last executed mysql query in laravel ?
- Laravel 5 Localization(trans helper) tutorial example
- AngularJS - Display Default image if original image does not exists with example
- How to create authentication(login and registration) in Laravel 5.2?
- Laravel 5 - user prevent common passwords using laravel-password package
- How to resolve laravel 5 blank page on server?
- How to get last record from MySQL table in Codeigniter?