Home > Net >  Codeigniter select where in array(0) { }
Codeigniter select where in array(0) { }

Time:10-17

I have the following query and it's working in MySQL

    SELECT
    t_pegtug.idtug 
FROM
    t_pegtug
    INNER JOIN
    t_tugas
    ON 
        t_pegtug.idtug = t_tugas.idtug
    INNER JOIN
    t_peg
    ON 
        t_pegtug.idpeg = t_peg.idpeg
WHERE
    t_tugas.tgl_pulang >= '2021-03-04' AND
    t_tugas.tgl_berangkat <= '2021-03-04' AND
    t_pegtug.idpeg IN ((
        SELECT
            t_pegtug.idpeg 
        FROM
            t_pegtug
            INNER JOIN t_tugas ON t_pegtug.idtug = t_tugas.idtug
            INNER JOIN t_peg ON t_pegtug.idpeg = t_peg.idpeg 
        WHERE
            t_tugas.idtug = '9' 
        ))

But if I convert the Codeigniter way then the query is not working. How can I write this query in Codeigniter? I tried the following code but it's showing

"Trying to get property of non-object"

 $query=$this->db->query('
   SELECT t_pegtug.idtug FROM t_pegtug 
   INNER JOIN  t_tugas  ON   t_pegtug.idtug = t_tugas.idtug 
   INNER JOIN t_peg ON  t_pegtug.idpeg = t_peg.idpeg  
   WHERE t_pegtug.idpeg in (
     SELECT t_pegtug.idpeg  FROM t_pegtug 
     INNER JOIN t_tugas ON t_pegtug.idtug = t_tugas.idtug 
     INNER JOIN t_peg ON t_pegtug.idpeg = t_peg.idpeg 
     WHERE t_tugas.idtug = "9" 
   ) 
   AND t_tugas.tgl_pulang >= "2021-03-04"  
   AND t_tugas.tgl_berangkat <= "2021-03-04" 
   ORDER BY t_tugas.idtug ASC');

return $query;

CodePudding user response:

Try to use the method result_array() like that $query->result_array()

  • Related