CodeIgniter Forums

Full Version: IF I want to add ( ) between condition, How I can do this?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
I use CI Active Database to select data from condition below

Code:
$this->select()->from('table')->where('fieldA != "dataA1"')->like('fieldB', $input)->or_like('fieldC',$input);

// Geberates QUERY
SELECT * FROM table WHERE fieldA != "dataA1" AND "fieldB" LIKE '%$input%' OR "fieldC" LIKE '%$input%';

but I want to Add (), becuase I don't want to show some data from first condition, but still show.
how I can do that

El Forum

[eluser]pickupman[/eluser]
Perhaps posting how you want the parenthesis to look in your final query would be helpful. What statements are you wanting to be inside of the parenthesis?

El Forum

[eluser]Unknown[/eluser]
[quote author="pickupman" date="1365194488"]What statements are you wanting to be inside of the parenthesis?[/quote]

As I understand it he is interested in how to create the following query:
Code:
SELECT * FROM table WHERE fieldA != "dataA1" AND ("fieldB" LIKE '%$input%' OR "fieldC" LIKE '%$input%');

El Forum

[eluser]Pert[/eluser]
At the moment there is no way to add brackets in Active Records.

The closest you can do is

Code:
$this->db->where('(table_a.col_a = \'a\' OR table_b.col_b = \'b\')', null, false);

You have to remember to escape your values manually.

El Forum

[eluser]jairoh_[/eluser]
u can use query bindings