Welcome Guest, Not a member yet? Register   Sign In
advanced sql query with grouping requests
#1

[eluser]endo[/eluser]
Hello, everyone!

How to construct next query with AR?

SELECT *
FROM (`realty_objects`)
WHERE (`district` = 'Manhatten' OR `district` = 'Brooklyn')
AND `size` >= '30'
AND `size` <= '40'
#2

[eluser]jmadsen[/eluser]
What does "AR" mean?
#3

[eluser]endo[/eluser]
Active Record
#4

[eluser]danmontgomery[/eluser]
Code:
$this->db->where('(district = "Manhatten" OR district = "Brooklyn")')
->where('size >=', 30)
->where('size <=', 40)
->get('realty_objects');
#5

[eluser]endo[/eluser]
Brilliant =)
#6

[eluser]jmadsen[/eluser]
or:

Code:
$sql = 'SELECT *
FROM (`realty_objects`)
WHERE (`district` = ‘Manhatten’ OR `district` = ‘Brooklyn’)
AND `size` >= ‘30’
AND `size` <= ‘40’ ';
$result = $this->db->query($sql);
return $result;

Since you've already written your sql :-)
#7

[eluser]daparky[/eluser]
Nice one, this has helped me alot.
#8

[eluser]Nick_MyShuitings[/eluser]
There was also a mod of AR floating around a while ago... I'll try and find it.

Basically added to methods you could use for chaining, open_group and close_group, which really didn't do anything else other then add an open and closing parenthesis. Allowed for using the AR syntax to write these complex type queries.
#9

[eluser]Nick_MyShuitings[/eluser]
This was the third request for this today... so here you go:

http://ellislab.com/forums/viewthread/177531/




Theme © iAndrew 2016 - Forum software by © MyBB