Welcome Guest, Not a member yet? Register   Sign In
Error Number 1054 Unknown column 'Array' in 'where clause'
#1

[eluser]dynZack[/eluser]
I'm getting the following error:


A Database Error Occurred
Error Number: 1054
Unknown column 'Array' in 'where clause'
SELECT `id`, `city` FROM (`cities`) WHERE `country_id` = Array


In the controller I call a MCountries::getCountryIDByCode

Code:
$active_countryID = $this->MCountries->getCountryIDByCode($active_country);

Code:
/*getCountryIDByCode*/
function getCountryIDByCode($country_code){
    $data = array();
    $this->db->select('id');
    $this->db->where('code', $country_code);
    $Q = $this->db->get('countries');
     if ($Q->num_rows() > 0){
         $row = $Q->row();
         $data = $row['id'];
    }
    $Q->free_result();  
    return $data;
}

And then call this:

Code:
$cities = $this->MCities->getCitiesByCountryDropDown($active_countryID)

Code:
/*getCitiesByCountryDropDown*/
function getCitiesByCountryDropDown($country_id){
     $data = array();
     $this->db->select('id,city');
     $this->db->where('country_id', $country_id);
     $Q = $this->db->get('cities');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[$row['id']] = $row['city'];
       }
    }
    $Q->free_result();  
    return $data;
     }
}


Doesn't getCountryIDByCode return a variable? Why am I getting this error?
#2

[eluser]WanWizard[/eluser]
You define $data as an array. If the query doesn't return a result, the empty array is returned.

As a rule, either always return the same type of value, or return FALSE when the method doesn't produce any results.
Also, if your method has multiple possible results, check the result before doing anything with it.
#3

[eluser]dynZack[/eluser]
Thanks!

I copied the code and haven't even saw that is declared as an array

....need to get some sleep.




Theme © iAndrew 2016 - Forum software by © MyBB