Issue
hello guys i need help understanding CodeIgniter, im new in framework i have this query builder inside a function
public function findLeader($where)
{
$this->db->select('me.EMP_FULL_NAME');
$this->db->from('tr_approval ta');
$this->db->join('m_employee me', 'me.EMP_ID = ta.EMP_ID');
$this->db->where($where);
//$namaLeader = $this->db->count_all_results();
$name = $this->db->get();
$name->row_array();
$name = $name['EMP_FULL_NAME'];
return $name;
}
and this code for call the function
$where = array(
'ta.RB_ID' => 'RB/210113/0001',
'ta.TR_APP_STATUS' => '0',
);
$getName = $this->Model_online->findLeader($where);
echo $getName;
but i got this 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\models\Model_online.php
Line Number: 38
pls help, im trying get only 1 row from the query builder but i cant
Solution
Since $name
is initially object and row_array()
is used to retrieve single row as array form you have to save it in a $variable
. You have to reassign the value of $name
:
$name = $this->db->get();
$name = $name->row_array();
$name = isset($name['EMP_FULL_NAME']) ? $name['EMP_FULL_NAME'] : 'Not Available';
or use this method:
$name = $this->db->get()->row_array();
$name = isset($name['EMP_FULL_NAME']) ? $name['EMP_FULL_NAME'] : 'Not Available';
Answered By - Hammad Ahmed khan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.