Professional CodeIgniter, Thomas Myer

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
c07.indd 193
c07.indd 193
6/10/08 5:36:38 PM
6/10/08 5:36:38 PM


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.

OK

Loading...
...
Закрыть