Welcome Guest, Not a member yet? Register   Sign In
IF I want to add ( ) between condition, How I can do this?
#1

[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
#2

[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?
#3

[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%');
#4

[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.
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB