Need help converting SQL statement to Active Records |
[eluser]Unknown[/eluser]
I don't know why I never used Codeigniter to develop websites, but I just started using it 2 weeks ago, and it is awesome! I've been a PHP developer for about 4 years now, and I know my way with basic SQL statements, but ever since reading this post http://ellislab.com/forums/viewthread/116566/ I now know that I've been doing SQL commands improperly, basically if I wanted to get information from 2 tables, I would query the primary table, then in a WHILE loop, I would query the Secondary table. I have taken Pixel888's SQL statement and modified it for a zip code radius that works well, everything is working great, but I want to do more Active Record SQL statements, and I have a problem trying to convert this (complicated to me) statement. I tried all I could to make it work myself, but I cannot get past it. Here is the SQL code that is working great inside my MODEL file. Code: function getLatLong($zipcode) { I want to be able to take that SQL code, and convert it into active record SQL, but I don't know where to start. I tried doing Code: $this->db->select('u.*, z.latitude, z.longitude, (3956 * 2 * ATAN2(SQRT(POW(SIN((RADIANS(latitude) - RADIANS(' . $lat . '))/2),2) + COS(RADIANS(' . $lat . ')) * COS(RADIANS(latitude)) * etc, etc... I would have written the rest, but the problem is, when I did the whole active record statement, and error came up on the view, and the SQL statement has single quotes around the beginning c.*, z.latitude, z.longitude, so I know it's not working. Any help would be greatly appreciated in the conversion. I actually don't know if this would be a join or not, since I have never worked with joins before, but I don't see a JOIN statement in the original SQL itself, unless it's shorthand JOIN. Thanks in advance! |
Welcome Guest, Not a member yet? Register Sign In |