CodeIgniter Forums
two dimensional array insert in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: two dimensional array insert in codeigniter (/showthread.php?tid=70978)



two dimensional array insert in codeigniter - kvanaraj - 06-24-2018

I have one task which two dimensional array of checkbox in db. In attached file shows clearly. that checkbox having values like 5001,5002,5003 each row accordingly. I want to insert that values accordingly to the corresponding regno values .

I want to insert the field like
insert into stud values(2010101001,5001);
insert into stud values(2010101001,5002);
insert into stud values(2010101001,5003);

insert into stud values(2010101002,5001);
insert into stud values(2010101002,5002);
insert into stud values(2010101002,5003);
only posted values to be insert 

my view file like
<?php
$sno=1;
foreach($getstud as $row)
  {
    echo '<tr>'; ?>
    <?php
    echo '<td>'.$sno++.'</td>';  
    echo '<td>'.$row['regno'].'</td>';
    echo '<td>'.$row['name'].'</td>';
    ?>
    <?php  ?>
    <?php  foreach($getsubc as $row1)
    {?>
      <td align="center"> <input type="checkbox" class="check" name="friend_id[]"
                value="<?php echo $row1['markid'];?>" >
              </td>

My controlle file

public function add_attend_studreg120(){
        $friend_ids_array = $this->input->post('friend_id'); //name of the checkbox.
        for($index=0; $index < count($friend_ids_array); $index++){
            $data[$index]['user_id'] = $friend_ids_array[$index];
        }
        $this->User_model->saveMessage($data);
        redirect(base_url().'studreg/');
    }

this method working but only values insert but regno field not inserted. it shows blank. how to get the values. Its a data tables not a post item . how to get it


RE: two dimensional array insert in codeigniter - InsiteFX - 06-25-2018

You could json encode and decode it then assign it to the data array
table column should be a text field.


RE: two dimensional array insert in codeigniter - kvanaraj - 06-25-2018

how to get those 2 values(regno,markid)