0

I'm trying to receive an array from a query "where_in" in Codeigniter:

$this->db->select('file_name');
$this->db->from('images_table');
$this->db->where_in('id', $id_array_img);

$result = $this->db->result_array();

print_r($result);

But doesn't work; why?

1
  • look at the active record documentation Commented May 25, 2014 at 12:24

1 Answer 1

1

Your have forgot to do the:

$this->db->get();


Your model should be like:

<?php
class Your_model extends CI_Model
{
    public $db;
    public function __construct()
    {
       parent::__construct();
       $this->db = $this->load->database('default',true);     
    }

    public function function_name()
    {
        $this->db->select('file_name');
        $this->db->from('images_table');
        $this->db->where_in('id', $id_array_img);            
        $query = $this->db->get();                   // add this

        $result = "";
        if($query->num_rows() > 0)
            $result = $query->result_array();
        else
            $result = "No result";

        print_r($result);
    }
}


Explanation:

Without $this->db->get();, you are just generating the query, but not firing it.

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

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.