Simple solution to complex where clause brace problen in Code-igniter


In Code-Igniter How do you make a query with where clause with a brace like following —

SELECT * FROM props 
WHERE `active` = 1
AND (rent >= 25 OR price >=25) AND 1=  1
AND `props`.`id` = '1'

Code-Igniter active record pattern does not generally support this type of query as far i searched.

I found a surprising solution for this type of query. for this query i make the where clause like following —

$this->db->where('(rent >= 25 OR price >=25) AND 1= ',1); 
$this->db->where('props.id',1); 

Which does the tricks.

I don’t actually know this is the fault of the developers or a feature but it is good for my work to move on.

so the total query for this SQL becomes —

$this->db->where('(rent >= 25 OR price >=25) AND 1= ',1); 
$this->db->where('props.id',1); 
$this->db->get('props');

cheers………

Advertisements
  1. I quite like reading through a post that can make people think.
    Also, thank you for permitting me to comment!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: