0
votes

I want to send 2 strings through array from controller to model and get the results from db, but there is a problem I'm facing.

My controller is like:

$data = array();
if($query = $this->authors_model->get_authors_list(array('author_Type' => array('admin', 'author'))))
{
    $data['authors'] = $query;
}

My Model :

function get_authors_list($options = array())
{        

    if(isset($options['author_Type']))
    $this->db->where('author_Type', $options['author_Type']);

    $this->db->order_by('author_Id', 'ASC');
    $query = $this->db->get('mg_authors');

    return $query->result();
}

and the error I'm getting:

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: database/DB_active_rec.php

Line Number: 427


Error Number: 1054

Unknown column 'Array' in 'where clause'

SELECT * FROM (mg_authors) WHERE author_Type = Array ORDER BY author_Id ASC LIMIT 15

Filename: D:\xampp\htdocs\sport\system\database\DB_driver.php

Line Number: 330

1
You are passing $options['author_Type'] array to AR::where() method, which generates author_Type = Array. that's an error. - Hashem Qolami

1 Answers

3
votes

You need to use WHERE IN when you put array. In CodeIgniter, it need to do like this:

$this->db->where_in('author_Type', $options['author_Type']);