Welcome Guest, Not a member yet? Register   Sign In
SQL query to Active Record
#1

[eluser]echoDreamz[/eluser]
I am trying to get this query converted to the Active Record class, so far no luck! Any help would be appreciated.

Code:
SELECT `code`, `name` FROM `country_ips` NATURAL JOIN `country_codes` WHERE *IP_GOES_HERE* BETWEEN `start` AND `end`
#2

[eluser]puzzlebox[/eluser]
I think it would be something like this:

$this->db->select('code,name')->from('country_ips')->join('country_codes')->where("$ip BETWEEN start AND end",NULL,FALSE);

reply if that doesn't work Smile

SELECT `code`, `name` FROM `country_ips` NATURAL JOIN `country_codes` WHERE *IP_GOES_HERE* BETWEEN `start` AND `end`
#3

[eluser]echoDreamz[/eluser]
Thanks @puzzlebox.

I came up with

$CI->db->select('code, name')->from('country_ips')->join('country_codes', 'country_ips.country_id = country_codes.country_id')->where("'{$ipaddr}' BETWEEN `start` AND `end`", NULL, FALSE)->limit(1);

So very similar to yours Smile. Works too Smile!




Theme © iAndrew 2016 - Forum software by © MyBB