Welcome Guest, Not a member yet? Register   Sign In
active record
#1

[eluser]toink[/eluser]
how to use record record like this...

Code:
$this->db->where('name !=', $name);
$this->db->or_where('id', '11');
$this->db->or_where('id', '10');

how to use active record to generate this query

where name != $name and (id > '11' OR id = 10)
#2

[eluser]Syllean[/eluser]
Code:
$this->db->where('name !=', $name);
$this->db->where('id >=', 10);

or

Code:
$where = "name!=$name AND id>=10";
$this->db->where($where);

or

Use query bindings:
Code:
$sql = "SELECT * FROM some_table WHERE name != ? AND id >= ? ";
$this->db->query($sql, array($name, 10));

The documentation for Codeigniter is really very good: http://ellislab.com/codeigniter/user-gui...ecord.html
#3

[eluser]toink[/eluser]
thanks for the solution, however i'm looking for something to group the ORs.

it should be name != $name AND (id = '10' or id = '11')

#4

[eluser]Pert[/eluser]
Code:
$this->db->where('name !=', $name)
   ->where_in('id', array(10, 11))
   ->get('table');
#5

[eluser]Syllean[/eluser]
[quote author="toink" date="1371197082"]thanks for the solution, however i'm looking for something to group the ORs.

it should be name != $name AND (id = '10' or id = '11')

[/quote]

In your original post you said (id > '11' or id = '10'), which is why I used id>=10, but for this query use where_in as Pert said above. He used method chaining but you can also use separate function calls if you prefer.




Theme © iAndrew 2016 - Forum software by © MyBB