This article is focused on fetch single row in php codeigniter. We will use codeigniter return one row database. this example will help you fetch one row value mysql codeigniter example. In this article, we will implement a codeigniter get single row.
I will give you simple example of fetch single record from database using mysql codeigniter.
Sometime we need to get only one record from database. might be you require to get last one row from database or fetch any single row using where or other condition. So just see bellow query how it make done.
Example:
$data = $this->db->get("items")->row();
print_r($data);
Output:
stdClass Object
(
[id] => 2
[title] => Codeigniter 3 CRUD Example
[description] => Codeigniter 3 CRUD Example From Scratch To follow : Itsolutionstuff.com
[created_at] => 0000-00-00 00:00:00
[updated_at] => 0000-00-00 00:00:00
)
You can get single fields value from object:
$data = $this->db->get("items")->row();
print_r($data->title);
I hope it can help you....
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example