1

I have a JOIN query in CodeIgniter which returns an empty array.

My Controller part:

if ($this->session->has_userdata('user')) {

    $id = $this->session->user['id'];

    $where = ["products.user_id =" => $id];

    $status = $this->insertModel->get_status($where);

    $this->load->view('profile', ["status" => $status]);
}

My model:

return $this->db
        ->from('photos')
        ->join('products', 'photos.prod_id = products.id', 'left')
        ->where($where)
        ->get()
        ->result_array();
1
  • 2
    ok.... and what are you wanting it to return? What is your question exactly? Commented Mar 30, 2019 at 19:05

2 Answers 2

2

in your controller, just send $id instead of $where

$status = $this->insertModel->get_status($id);

and rebuild your where clause in your model the Codeigniter way:

->where('products.user_id', $id)

see the docs here

and about MVC (Model=database interaction, View=browser output and Controller=your application logic)

Sign up to request clarification or add additional context in comments.

Comments

0

Controller:
Your error is in $where, check my code

if ($this->session->has_userdata('user')) {

    $id = $this->session->user['id'];

    //$where = ["products.user_id =" => $id];//old line
    $where = array("products.user_id" => $id);//new line

    $status = $this->insertModel->get_status($where);

    $this->load->view('profile', ["status" => $status]);
}

Comments

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.