Welcome Guest, Not a member yet? Register   Sign In
Activerecord WHERE $field PLUS $field EQUALS $value. Is this possible?
#1

[eluser]Andy UK[/eluser]
Hi all,

I have two types of parking spaces in my database. Individual spaces and double spaces where you have to move one car to get the other out. The sum of the individual parking spaces plus the double spaces gives me the total parking spaces available per property.

When querying the database, it's easy enough to return the total with something like this:

$this->db->select("property.parking_double + property.parking_individual as parking");

Trouble is, I'm not able to do the same with the where clause when querying for properties with a certain number of total parking spaces. This for example is not working:

$this->db->where('parking_individual + parking_double =', $this->session->userdata('parking'));

Is this possible or will i have to sum the two fields in the controller for every function that needs this result?

Thanks!
#2

[eluser]Andy UK[/eluser]
I've just discovered that the above code is possible and does work. The error was elsewhere.




Theme © iAndrew 2016 - Forum software by © MyBB