phpcodeignitermodel

CodeIgniter model method emits Notice: Array to string


This appears mensagem: Severity: Notice Message: Array to string conversion

my model

public function get_parcelasvencidas()
{
    $today = date('Y-m-d');
    $id = $this->session->userdata('user_id');
    $query = $this->db->query("SELECT * FROM parcelas, aluguel WHERE id_aquiler_parcelas = id_alug");
    return $query->result();
}

Solution

  • First of all, your query is seems wrong. Change with this :

    $this->db->query("SELECT * FROM parcelas, aluguel WHERE id_aquiler_parcelas = 'id_alug'");
    

    Because id_alug is value, not variable.

    Second, you get an error like this :

    Message: Array to string conversion

    Because your return type in model is an object. To get the result use foreach instead, like this :

    foreach($this->my_model->get_parcelasvencidas() as $row)
    {
        echo $row->id;
        echo $row->name;
    }