I am trying to get the max value from a database table via this CodeIgniter query:
$this->db->select_max('product_id');
$this->db->from('products');
$query = $this->db->get();
return $query->result();
But when I add this array of objects to to my next query, I get an error:
$this->db->insert('images', $product_id);
It show this error:
Error Number: 1054
Unknown column 'Array' in 'field list'
INSERT INTO
images(product_id) VALUES (Array)Filename: C:\wamp\www\system\database\DB_driver.php
Line Number: 330
When I did var_dump(), it showed:
array(1) {
["product_id"]=> array(1) {
[0]=> object(stdClass)#21 (1) {
["product_id"]=> string(2) "26"
}
}
}
$product_idis an array, useprint_r($product_id)to see which values it contains.$this->db->insert('images', $this->db->select_max('product_id')->get('products')->row_array());this should provide a flat array. Although such practice seems vulnerable to race conditions.