How to Get Single Row from Database in Codeigniter?
If you require to get only one record from database table using codeigniter query then you can do it using row(). we can easily return one row from database in codeigniter.
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....
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Create a Custom Library in CodeIgniter?
- Codeigniter Crop Image Before Upload Example
- Codeigniter Form Submit using Ajax Request Example
- How to Get Last Executed Query in Codeigniter?
- How to Get All Tables List in Codeigniter?
- Codeigniter Dynamic Highcharts Example
- Codeigniter Ajax Pagination using JQuery Example
- How to Create Dynamic Sitemap in Codeigniter?
- Codeigniter Drag and Drop Multiple Image Upload Example
- How to Get Current Controller or Method Name in Codeigniter?
- How to Get Last Record in Codeigniter?
- How to Get Last Inserted ID in Codeigniter?
- How to Get Current URL with Query String in Codeigniter?