How to make a database information array in codeigniter

Asked

Viewed 30 times

0

For example, I am sending an id array [0] => 1, [1] => 3 and I want to show this in my html as a result. In the case that you search in the database with the first id save in the array and then search with the second id and finally return an array containing the other two arrays.

    public function getRecibos($codigosRecibo)
{      
    $result = array('');

    foreach ($codigosRecibo as $codigoRecibo)
    {
        $this->db->select('*'); 
        $this->db->where('idRecibo', $codigoRecibo);
        $this->db->join('cheque', 'cheque.idCheque = recibo.recibo_idCheque', 'left');
        $this->db->from('recibo');
        $result = $this->db->get();
    }       
        return $result->result();
}

1 answer

0


I think just do this

public function getRecibos($codigosRecibo)
{      
    $result = [];

    foreach ($codigosRecibo as $codigoRecibo)
    {
        $result[] = $this->db->query('select * from recibo
                                      where idRecibo = ?
                                      left join cheque
                                      on cheque.idCheque = recibo.recibo_idCheque',
                                      array($codigoRecibo))->row();
    }       
        return $result;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.