Chapter 7: Improving the Dashboard
193
with array_values() and implode() (using the comma as a glue) and feed that list to the
$this- > db- > where() method.
Here ’ s the whole batchUpdate() function:
function batchUpdate(){
if (count($this- > input- > post(‘p_id’))){
$data = array(‘category_id’ = > $this- > input- > post(‘category_id’),
‘grouping’ = > $this- > input- > post(‘grouping’)
);
$idlist = implode(“,”,array_values($this- > input- > post(‘p_id’)));
$where = “id in ($idlist)”;
$this- > db- > where($where);
$this- > db- > update(‘products’,$data);
$this- > session- > set_flashdata(‘message’, ‘Products updated’);
}else{
$this- > session- > set_flashdata(‘message’, ‘Nothing to update!’);
}
}
At this point, feel free to test out your new functionality. Notice that this batch update entirely replaces
the category_id and grouping fields for the selected products. In other words, if certain products
already have settings, this batch mode process will overwrite what ’ s there.
When you submit your form results, you should see something similar to Figure 7 - 2.
Figure 7-2