Welcome Guest, Not a member yet? Register   Sign In
Error Number: 1054 - Unknown column '2' in 'field list'
#1

[eluser]Nexus Rex[/eluser]
An integer in my active record query is being mistaken for a column. I am using the POWER function in mySQL, and the power of 2 is being mistaken for a column called 2.

Here is my code:
Code:
$this->db->select('DISTINCT locations.id, locations.location_number, locations.name, locations.street_address, locations.street_address_line2, locations.city, locations.state_province, locations.zip_postal_code, locations.country, locations.phone, locations.toll_free, locations.fax, locations.email, locations.website_url, locations.contact_name, locations.contact_title, locations.additional_info, locations.image, us_ca_codes.latitude, us_ca_codes.longitude, (3956 * 2 * ASIN(SQRT(  POWER(SIN((' . $mylocal->point->latitude . ' - us_ca_codes.latitude) * pi()/180 / 2), 2) + COS(' . $mylocal->point->latitude . ' * pi()/180) *  COS(us_ca_codes.latitude * pi()/180) *  POWER(SIN((' . $mylocal->point->longitude . ' - us_ca_codes.longitude) * pi()/180 / 2), 2)  )) ) AS distance');


Here is my error:
Code:
A Database Error Occurred

Error Number: 1054

Unknown column '2' in 'field list'

SELECT DISTINCT locations.id, locations.location_number, locations.name, locations.street_address, locations.street_address_line2, locations.city, locations.state_province, locations.zip_postal_code, locations.country, locations.phone, locations.toll_free, locations.fax, locations.email, locations.website_url, locations.contact_name, locations.contact_title, locations.additional_info, locations.image, us_ca_codes.latitude, us_ca_codes.longitude, (3956 * 2 * ASIN(SQRT( POWER(SIN((40.837299 - us_ca_codes.latitude) * pi()/180 / 2), 2) + COS(40.837299 * pi()/180) * COS(us_ca_codes.latitude * pi()/180) * POWER(SIN((-111.919323 - us_ca_codes.longitude) * pi()/180 / 2), `2`) )) ) AS distance FROM (`locations`) LEFT JOIN `accounts` ON locations.account_id = accounts.id LEFT JOIN `us_ca_codes` ON locations.zip_postal_code = us_ca_codes.zip_postal_code WHERE accounts.username = 'test02' AND us_ca_codes.latitude BETWEEN '40.331314' AND '41.343284' AND us_ca_codes.longitude BETWEEN '-112.425311' AND '-111.413335' ORDER BY locations.location_number asc, locations.id asc LIMIT 4

Any thoughts?
#2

[eluser]Derek Allard[/eluser]
What happens if you add FALSE as a second parameter? You can read more about it at http://ellislab.com/codeigniter/user-gui...tml#select
#3

[eluser]Nexus Rex[/eluser]
Works like a charm.

Thank you!
#4

[eluser]Derek Allard[/eluser]
My pleasure Travis.




Theme © iAndrew 2016 - Forum software by © MyBB