Today, We want to share with you how to fetch single data from database in codeigniter?.In this post we will show you Codeigniter – get only 1 row from table, hear for Generating Query Results — CodeIgniter 4.0.4 we will give you demo and example for implement.In this post, we will learn about Select Query In Codeigniter Example Tutorial with an example.
How to fetch single row from database in php 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.
Fetch Single Row From Database in Codeigniter
Example
$data = $this->db->get("tamilrockers")->row(); print_r($data);
Results:
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 )
get single fields value from object:
$data = $this->db->get("tamilrockers")->row(); print_r($data->title);
Getting a single value from database – Codeigniter
Controller
public function members() { if($this->session->userdata('is_logged_in')) { $email = $this->input->post('email'); $result = $this->mymodel->getnames($email); if($result){ $data['fname'] = $result->first_name; $data['lname'] = $result->last_name; $this->load->view('members', $data); } } else { redirect('main/restricted'); } }
public function getnames($email) { $this->db->where('email',$email); $query = $this->db->get('users'); if($query->num_rows == 1) { return $query->row(); } return false; }
I hope you get an idea about return one row from database in codeigniter..
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.