0

I'm trying to display an result from the database to the view but I keep getting this error:

Severity: Notice

Message: Array to string conversion

Filename: database/DB_query_builder.php

Line Number: 683

Backtrace:

File: C:\xampp\htdocs\konsultasi\application\models\m_data.php Line: 32 Function: where

File: C:\xampp\htdocs\konsultasi\application\controllers\Page.php Line: 131 Function: lihat_data

this my model (m_data)

function lihat_data($id)
{
    $param = array('id' => $id);
    $this->db->select('tiket.subjek,siswa.nama,tiket_isi.created,tiket_isi.isi');
    $this->db->from('tiket');
    $this->db->join('siswa', 'tiket.dari=siswa.nis');
    $this->db->join('tiket_isi', 'tiket.id=tiket_isi.tiket_id');
    $this->db->where('siswa.nis', $param);
    $query = $this->db->get();
    return $query;
}

and this my controller

function lihat($idx)
{
    $id     = $this->uri->segment(3);
    $where = array('id' => $idx);
    $data['row']   = $this->db->get_where('tiket', array('id' => $id))->row_array();
    $data['user'] = $this->m_data->lihat_data($where, 'tiket')->result();
       
    $this->load->view('templates/header');
    $this->load->view('konsul/lihat', $data);
    $this->load->view('templates/footer');
}

and view code

<div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">
                <?= $row['subjek']; ?>
            </h6>
        </div>
        <div class="card-body">
            <?php foreach ($user as $u) { ?>
                <div class="col-lg mb-4">
                    <div class="card bg-primary text-white shadow">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-6">
                                    <p><?= $u->nama ?></p>
                                </div>
                                <div class="col-lg-6">
                                    <p><?= $u->created ?></p>
                                </div>
                            </div>
                            <div class="text-white-80 small mt-2"><?= $u->isi ?></div>
                        </div>
                    </div>
                </div>
            <?php } ?>
1
  • The Error message indicates that you have an issue with your WHERE statement.So you should head on over to the CI 3 User Guide and see where you are going wrong - codeigniter.com/userguide3/database/… Commented Oct 25, 2020 at 7:49

1 Answer 1

1

You can not add an array like that to where statement, this is wrong

$param = array('id' => $id);
$this->db->where('siswa.nis', $param);

it should be like

$this->db->where('id', $id);
$query = $this->db->get('table_name');

or like

$param = array('id' => $id);
$this->db->where($param);
$query = $this->db->get('table_name');
Sign up to request clarification or add additional context in comments.

3 Comments

The Op could also use $this->db->where($param); even though $param is a bad choice for a variable name in this case.
maybe it means like this $param = ['siswa.nis' => $id]; $this->db-where($param); this is just my opinion.
but you can very well: $param = array('id' => $id); $this->db->where($param);see associative array method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.