ItSolutionStuff.com

How to Get Single Row from Database in Codeigniter?

By Hardik Savani • November 5, 2023
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

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Create a Custom Library in CodeIgniter?

Read Now →

Codeigniter Crop Image Before Upload Example

Read Now →

Codeigniter Form Submit using Ajax Request Example

Read Now →

How to Get Last Executed Query in Codeigniter?

Read Now →

How to Get All Tables List in Codeigniter?

Read Now →

Codeigniter Dynamic Highcharts Example

Read Now →

Codeigniter Ajax Pagination using JQuery Example

Read Now →

How to Create Dynamic Sitemap in Codeigniter?

Read Now →

Codeigniter Drag and Drop Multiple Image Upload Example

Read Now →

How to Get Current Controller or Method Name in Codeigniter?

Read Now →

How to Get Last Record in Codeigniter?

Read Now →

How to Get Last Inserted ID in Codeigniter?

Read Now →

How to Get Current URL with Query String in Codeigniter?

Read Now →