简体   繁体   中英

Query Builder With Join CodeIgniter, return 1 row

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

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM