[eluser]gbar[/eluser]
Hello and thank you for reply to me. Unfortunately your solution, despite having tried in various ways, also gives me a strange behavior.
I try to explain it.
I leave the code of the form:
Code:
<?php echo form_hidden('status[]', $rows->status); ?>
<?php
$data = array(
'name' => 'upd_id[]',
'value' => $rows->id_book
);
?>
<?php echo form_checkbox($data); ?>
This, however, is the part on the controller. I entered the print_r to see what happens.
Code:
// other code.....
}
else
{
$status = $this->input->post('status');
foreach($this->input->post('upd_id') as $key => $val){
echo 'upd_id: ' . $val . ' - status: ' . $status[$key] . '<br />';
}
echo'<br />';
print_r($upd_id);
echo'<br />';
print_r($status);
//$this->statusBooksBatch($sortBy, $sortOrder, $page, $upd_id, $status);
}
// other code.....
Now let's take a couple of examples
The scenario is to have 4 records, the first and third with status = 0, the second and fourth with status = 1.
Like this:
Code:
Record id: 242 - status 0
Record id: 241 - status 1
Record id: 240 - status 0
Record id: 239 - status 1
First case, I select all the checkboxes, I get this:
Code:
upd_id: 242 - status: 0
upd_id: 241 - status: 1
upd_id: 240 - status: 0
upd_id: 239 - status: 1
Array ( [0] => 242 [1] => 241 [2] => 240 [3] => 239 )
Array ( [0] => 0 [1] => 1 [2] => 0 [3] => 1 )
correct!
Second case, I select the first two:
Code:
upd_id: 242 - status: 0
upd_id: 241 - status: 1
Array ( [0] => 242 [1] => 241 )
Array ( [0] => 0 [1] => 1 [2] => 0 [3] => 1 )
correct!
But if I select the second and third checkbox, the values are incorrect.
Code:
upd_id: 241 - status: 0
upd_id: 240 - status: 1
Array ( [0] => 241 [1] => 240 )
Array ( [0] => 0 [1] => 1 [2] => 0 [3] => 1 )
Incorrect!
The same if I select only the fourth.
Code:
upd_id: 239 - status: 0
Array ( [0] => 239 )
Array ( [0] => 0 [1] => 1 [2] => 0 [3] => 1 )
Incorrect!
In practice, everything is correct if I select all or some but always selecting the first.
if I select the second checkbox on, the value of status will always start from the first index and everyway, making no more values coincide.
I hope that I explained. Sorry for the length of the post.
Thank you very much!