Welcome Guest, Not a member yet? Register   Sign In
Complex SQL -> converting to active records
#5

[eluser]JamesTaylor[/eluser]
Thanks Phil, got it working with ActiveRecords using the following... so i now have working in both fashions which is comforting and confidence building!

Code:
$this->db->select('ClubID, Name, Lat, Lng, Address1, Address2, Address3, County, PostCode, TelArea, TelNo, Web, Email, Review')
         ->select('"( 3959 * acos( cos( radians($Lat) ) * cos( radians( Lat ) ) * cos( radians( Lng ) - radians($Lng) ) + sin( radians($Lat) ) * sin( radians( Lat ) ) ) )" AS distance');
$this->db->having('distance < ' .$Dist);
$this->db->order_by('distance');
$this->db->limit($LimitValue, $OffsetValue);
$query = $this->db->get('golfcourses');

a couple of things i notice with your sample...

you don't declare '$this->db' again after the inital '$this->db->select' statement i didn't realise it could be done this way, is it common / good / better practice to implement your style than the repetition that i use?

I note that in the code i have supplied which works as it is shown, if i have
Code:
$this->db->select(........
$this->db->select(........
$this->db->having(........
it throws up an error when it tries to execute, but when it is
Code:
$this->db->select(........
         ->select(........
$this->db->having(........
It works??

The other thing i don't quite follow is the 'FALSE' you have included at the end of the 2nd ->select() line. What is its purpose?

Thanks again for the reply!


Messages In This Thread
Complex SQL -> converting to active records - by El Forum - 12-10-2009, 09:30 AM
Complex SQL -> converting to active records - by El Forum - 12-10-2009, 10:05 AM
Complex SQL -> converting to active records - by El Forum - 12-10-2009, 10:46 AM
Complex SQL -> converting to active records - by El Forum - 12-10-2009, 10:47 AM
Complex SQL -> converting to active records - by El Forum - 12-10-2009, 11:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB