i have this problem
this is the display from my view.php
id menu +1 +2 +3
1 bla_1 [] [] []
2 bla_2 [] [] []
3 bla_3 [] [] []
and this is my view code
<?php $i=1; foreach ($test as $row) : ?>
<tr>
<td><input type='hidden' name='id[]' value="<?php echo $row->menu_id ?>" /></td>
<td><input type="text" name="Menu" value="<?php echo $row->menu_nama ?>" disabled <td>
<td><input type="checkbox" name="<?php echo 'menu_id[]'; ?>" value="+1" /></td>
<td><input type="checkbox" name="<?php echo 'menu_id[]'; ?>" value="+2" /></td>
<td><input type="checkbox" name="<?php echo 'menu_id[]'; ?>" value="+3" /></td>
</tr>
<?php $i++; endforeach ; ?>
if i check the first checkbox i will get +1, the second checkbox i will get +2
my goal is to join the input from every checked checkbox and save to database based on id
and this is my code on model to join the value of checkbox
$menu_id= $this->input->post('menu_id');
$menu_idc = '';
$count = count($menu_id);
$i=0;
foreach($menu_id as $e){
if($i < $count -1)
{
$menu_idc .= $e.'';
echo $i ;
}
else{
$menu_idc .= $e.'+';
}
$i++;
}
var_dump($menu_idc);
die;
from example if i check this checkbox
id menu +1 +2 +3
1 bla_1 [v] [v] [v]
2 bla_2 [] [v] []
3 bla_3 [] [] [v]
with code i write i will get +1+2+3+2+3+ (+1+2+3 from row 1, +2 from row 2, +3 from row 3)
what i want is to get is value from every row and save to table on database
+1+2+3+ save into database
+2+ save into database
+3+ save into database
Database
id | isi |
1 | +1+2+3+ |
2 | +2+ |
3 | +3+ |
i think i must loop the code on my model but i dont know what code i have to write
What you need is a 2-dimensional array. The first dimension is for the row and the second one is for the columns.
First change your markup a bit to make the submitted values 2-dimensional:
This code should work fine: