Search code examples
phpcodeignitercodeigniter-2

Codeigniter 2.2.6 find min value from sql column


I have an error:

Array to string conversion

In my model I have this:

public function get_min(){      
    $this->db->select_min('sq_place');
    $query = $this->db->get('places');
    return $query->result();    
}

In my dump data I got this:

array (size=1)
  0 => 
    object(stdClass)[32]
      public 'sq_place' => string '110' (length=3)

I use CodeIgniter v 2.2.6. How to convert this to string like 110 without errors?


Solution

  • Use

    $result = $query->result_array() ; // to get response as array.
    

    Then. Access your string value as

    $val = $result[0]['sq_place'];
    echo $val; //This should print your string val and wont give mentioned error