ggilrandy
ggilrandy

Reputation: 28

Get 1 row only from MySQL in CodeIgniter

i want to take only 1 row from database with no loop when i call it. this is my code on CodeIgniter

$row = $this->db->get_where('tr_supervision',array('EMP_ID_MEMBER' => $EMP_ID));
    
    echo $row['EMP_ID_LEADER'];

i dunno how but i get the error

An uncaught Exception was encountered Type: Error

Message: Cannot use object of type CI_DB_mysqli_result as array

Filename: C:\laragon\www\onlineform\application\controllers\Reimbursement.php

Line Number: 96

Backtrace:

File: C:\laragon\www\onlineform\index.php Line: 315 Function: require_once

Upvotes: 0

Views: 47

Answers (2)

Hammad Ahmed khan
Hammad Ahmed khan

Reputation: 1671

$this->db->where('EMP_ID_MEMBER',$EMP_ID)
         ->get('tr_supervision')
         ->row_array();

Upvotes: 0

marcogmonteiro
marcogmonteiro

Reputation: 2182

In that case your use it like this:

$row = $this->db->where('EMP_ID_MEMBER',$EMP_ID)
         ->get('tr_supervision')
         ->row_array();

echo $row['EMP_ID_LEADER'];

Please read more about query results here: https://codeigniter.com/userguide3/database/results.html?highlight=query%20results

Upvotes: 2

Related Questions