I have variable array($avail) like this :
$avail = [
['item_id' => 1, 'qty_avail' => 44],
['item_id' => 4, 'qty_avail' => 33],
['item_id' => 6, 'qty_avail' => 50],
];
And I want select with CodeIgniter:
$this->db->select(
'item_id,'
. $avail[0]['qty_avail'] . ' as "qty_avail",
qty_tocome, qty_togo'
);
$this->db->order_by('item_id', 'asc');
$this->db->where('item_category_id = ', $category_id);
$query = $this->db->get('t_inventory i', $limit, $offset)->result_array();
print_r($query);
The result is all [qty_avail] always $avail[0] :
Array (
[0] => Array
(
[item_id] => 1
[qty_avail] => 44
[qty_tocome] => 0.00
[qty_togo] => 0.00
)
[1] => Array
(
[item_id] => 4
[qty_avail] => 44
[qty_tocome] => 0.00
[qty_togo] => 0.00
)
[2] => Array
(
[item_id] => 6
[qty_avail] => 44
[qty_tocome] => 0.00
[qty_togo] => 0.00
)
);
But I want the qty_avail value which relates to each item_id, like this:
Array (
[0] => Array
(
[item_id] => 1
[qty_avail] => 44
[qty_tocome] => 0.00
[qty_togo] => 0.00
)
[1] => Array
(
[item_id] => 4
[qty_avail] => 33
[qty_tocome] => 0.00
[qty_togo] => 0.00
)
[2] => Array
(
[item_id] => 6
[qty_avail] => 50
[qty_tocome] => 0.00
[qty_togo] => 0.00
)
);