Codeigniter Batch Update For Checkbox
I have a situation like this, I want to update some data where the input are checkboxes, I was tried this code below. Data already saved in database, but data saved in another row,
Solution 1:
Controller Code:-
for($x = 0; $x < sizeof($birds); $x++){
$reslt[$x] = array(
"birds" => $birds[$x],
"qtt" => $qtt[$x],
"red" => $red[$x],
"blue" => $blue[$x],
"grey" => $grey[$x],
"yellow" => $yellow[$x],
"dark" => $dark[$x]
);
}
$this->db->update_batch('db_birds', $reslt, 'birds');
Change is in your view code:-
<?php//sql Query.//execute Query.$ii=0;
foreach($dpsas$dp){
$iii = $ii++;
<tr>
<td><input type="hidden" name="birds[<?php echo $iii;?>]" value='<?php echo $dp['birds']; ?>' /><?phpecho$dp['birds']; ?></td><td><palign='center'><inputtype="text"name="qtt[]"value='<?phpecho$dp['qtt']; ?>'tabindex="2"style="width:30px;" /></td><td><palign='center'><inputtype="checkbox"name="red[<?phpecho$iii;?>]"value='1'<?phpif($dp['red']==1) { echo" checked=\"checked\""; } ?> /></td><td><palign='center'><inputtype="checkbox"name="blue[<?phpecho$iii;?>]"value='1'<?phpif($dp['blue']==1) { echo" checked=\"checked\""; } ?> /></td><td><palign='center'><inputtype="checkbox"name="grey[<?phpecho$iii;?>]"value='1'<?phpif($dp['grey']==1) { echo" checked=\"checked\""; } ?> /></td><td><palign='center'><inputtype="checkbox"name="yellow[<?phpecho$iii;?>]"value='1'<?phpif($dp['yellow']==1) { echo" checked=\"checked\""; } ?> /></td><td><palign='center'><inputtype="checkbox"name="dark[<?phpecho$iii;?>]"value='1'<?phpif($dp['dark']==1) { echo" checked=\"checked\""; } ?> /></td></tr>
}
?>
Post a Comment for "Codeigniter Batch Update For Checkbox"