Welcome Guest, Not a member yet? Register   Sign In
CI pass array to model where clause
#1

Anyone can help me with this problem here? http://stackoverflow.com/questions/34704...ere-clause

Basically, I want it to look like this: UPDATE table SET active = 0 WHERE row_id = 1 OR row_id = 2 OR row_id = 3... Where in the row_id are from the array in controller.
Reply
#2

$this->db->where_in( 'row_id', array('1','2','3') );
Reply
#3

(01-10-2016, 09:25 PM)skunkbad Wrote: $this->db->where_in( 'row_id', array('1','2','3') );

Hello dear,

I am stuck in a condition.

I have array of keywords like array('business','permanent')

now can you please tell me how to pass this array into where clause
because where_in is only valid for ids(integers)

and when i am using the below statement it through error

$this->db->where('Keyword',array('business','permanent')) ;
or
$this->db->or_where('Keyword',array('business','permanent')) ;
or
$this->db->or_where(array('business','permanent')) ;


Please help
Thank you.
Reply
#4

(This post was last modified: 08-07-2018, 08:09 AM by Wouter60.)

Did you try
PHP Code:
where_in('Keyword', array('business','permanent')); 
?
Reply
#5

(08-07-2018, 08:08 AM)Wouter60 Wrote: Did you try
PHP Code:
where_in('Keyword', array('business','permanent')); 
?

yes but its not working thank you
Reply
#6

@mubashir,

What database are you using? also, have the system kick out the sql that it is generating so that we can see what it is doing?
Reply
#7

(08-08-2018, 07:14 AM)php_rocs Wrote: @mubashir,

What database are you using?  also, have the system kick out the sql that it is generating so that we can see what it is doing?

mysql
Reply
#8

@mubashir,

Did you get the generated sql? If you did, can you please show it. This will allow us to see how the system is generating the SQL.
Reply
#9

(This post was last modified: 09-17-2018, 12:34 PM by InsiteFX.)

Try this and see if it is what you want.

PHP Code:
$where "Keyword = 'business' OR Keyword = 'permanent'";
$this->db->where($where); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

Are you absolutely sure the table field is "Keyword" (with capital K)? MySQL is case-sensitive regarding field names.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB