I have a table menu w/c contains of(recipe_id,ingredient_id,category_id).I was trying to update my ingredients yet it only update 1 ingredient_id. Like this
Here is my code:
CONTROLLER:
public function save_edit_recipe()
{
foreach ($this->input->post('ingredients') as $key => $value) {
$menuData[] = array(
'recipe_id' => intval($this->input->post('recipe_id')),
'ingredient_id' => intval($value),
'category_id' => intval($this->input->post('recipe_category'))
);
}
// var_dump($menuData); die();
$this->products_model->updatemenu($menuData);
}
menudata is:
Array (
[0] => Array (
[recipe_id] => 2
[ingredient_id] => 1
[category_id] => 3
)
[1] => Array (
[recipe_id] => 2
[ingredient_id] => 2
[category_id] => 3
)
)
MODEL:
public function updatemenu($data)
{
foreach ($data as $row => $value) {
$this->db->where('ingredient_id', $data['ingredient_id']);
$query = $this->db->update('menu', $value);
}
return $result;
}
