CodeIgniter Forums
Error Number 1054 Unknown column 'Array' in 'where clause' - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Error Number 1054 Unknown column 'Array' in 'where clause' (/thread-32777.html)



Error Number 1054 Unknown column 'Array' in 'where clause' - El Forum - 08-04-2010

[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?


Error Number 1054 Unknown column 'Array' in 'where clause' - El Forum - 08-04-2010

[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.


Error Number 1054 Unknown column 'Array' in 'where clause' - El Forum - 08-04-2010

[eluser]dynZack[/eluser]
Thanks!

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

....need to get some sleep.