Skip to content
Advertisement

CodeIgniter – How to combine where() and where_not_in() in one query?

In one of my CodeIgniter based application, I need to combine both where() and where_not_in() in one single query. The query I wrote is:

JavaScript

Here:

  1. $open_ticket is sent from views and is either 0 or 1,
  2. getStatusIdByStatusName(status_name) returns the primary_id from status table
  3. $project_code, $page_no, $limit is sent from views

So when I test the result, it does not filter the data as expected, that’s why I print the generated query by CodeIgniter, and here it is:

JavaScript

as you can see, it doesn’t include the condition of where_not_in() . I can’t figure out how to solve this problem!

Can anyone tell me how can I combine both where() and where_not_in() in one single query.

  • Thanks

Advertisement

Answer

Your where_not_in() should have two arguments – first being the key tic.status_id and the second being the array.

Change your $where_not_in assignment to:

JavaScript

And the where_not_in() call to:

JavaScript

where_not_in() does not support the same associative array argument like where().

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement