how to insert array of data in to mysql database using codeigniter php :                 My problem is that array data are not inserted in database only last data are inserted. so how to insert whole data at a time after click save button. Please solve this issue ASAP. 
        
        I am new in codegniter soplease help us because i am try one day ago but  problem is still just.. so please check and solve it ...    
                
            //    Here is my Controller Part... Please review this code. if any thing are mistake so please correct. 
                   # Controller
                        
                        function index(){
                        	$this->session->set_userdata('top_menu', 'Attendance');
                                $this->session->set_userdata('sub_menu', 'teacherattendance/index');
                                $teacher_result = $this->teacher_model->get();
                                $data['teacherlist'] = $teacher_result;
                               
                                $this->form_validation->set_rules('stime', 'In Time', 'trim|required|xss_clean');
                                $this->form_validation->set_rules('etime', 'Out Time', 'trim|required|xss_clean');
                                if ($this->form_validation->run() == FALSE) { 
                        	$this->load->view('layout/header', $data);
                        	$this->load->view('admin/teacherattendance/attendenceList', $data);
                        	$this->load->view('layout/footer', $data);
                                } else {
                        		$data = array(
                                        'in_time' =>$this->input->post('stime'),
                                        'out_time' => $this->input->post('etime'),
                                        'teacher_id' => $this->input->post('teacter_id'),
                                        //'teacher_name' => $this->input->post('teacher_name')
                                        ); 
                        
                        	$this->load->model('teacherattendance_model');
                        	$insert_id = $this->teacherattendance_model->add($data);
                        	$this->session->set_flashdata('msg', '<div class="alert alert-success">Attendance added Successfully</div>');
                                   redirect('admin/teacherattendance');
                        	
                        	}
                        	}
                        // Please Solve this issue ASAP. 
              //  Here My Model Part So please Check...  This project for school erp so please check carefully . 
        if any one want the code so please correct this problem and contact this mail id sratanveer@yahoo.com this is my personal email id so please chek it and correct problem soon ...
        So please check this model  
                        #Model
                        
                        public function add($data) {
                                if (($data['id']) != 0) {
                                    $this->db->where('id', $data['id']);
                                    $this->db->update('teacher_attendance', $data); // update the record
                                } else {
                                    $this->db->insert('teacher_attendance', $data); // insert new record
                                    return $this->db->affected_rows();
                                }
                            }
                    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
    so every people are justify this problem 
    Here is my View Part So plese check...This is View part so please help this one .  
Here is my View Part So plese check...This is View part so please help this one .  
so every people are justify this problem 
Here is my View Part So plese check...This is View part so please help this one .  
so every people are justify this problem 
Here is my View Part So plese check...This is View part so please help this one .  
so every people are justify this problem Here is my View Part So plese check...This is View part so please help this one .  
so every people are justify this problem 
Here is my View Part So plese check...This is View part so please help this one .  
so every people are justify this problem 
Here is my View Part So plese check...This is View part so please help this one .  
so every people are justify this problem 
Here is my View Part So plese check...This is View part so please help this one .  
so every people are justify this problem 
Here is my View Part So plese check...This is View part so please help this one .  
so every people are justify this problem 
Here is my View Part So plese check...This is View part so please help this one  
                    # View 
                    
                    <style type="text/css">
                        @media print
                        {
                            .no-print, .no-print *
                            {
                                display: none !important;
                            }
                        }
                    </style>
                    
                    <div class="content-wrapper" style="min-height: 946px;">  
                        <section class="content-header">
                            <h1>
                                <i class="fa fa-mortar-board"></i> Teacher Attendance <small><?php echo $this->lang->line('student_fees1'); ?></small></h1>
                        </section>
                        <!-- Main content -->
                        <section class="content">
                            <div class="row">       
                                 
                                <div class="col-md-12">              
                                    <div class="box box-primary" id="tachelist">
                                        <div class="box-header ptbnull">
                                            <h3 class="box-title titlefix"><?php echo $this->lang->line('teacher_list'); ?></h3>
                    <div class="box-tools pull-right">
                                                <a href="<?php echo base_url(); ?>admin/teacherattendance/import" class="btn btn-primary btn-sm"  data-toggle="tooltip" title="Bulk Upload Teacher Attendance" >
                                                    <i class="fa fa-upload"></i>Import Teacher Attendance
                                                </a>
                                            </div>     
                    <div class="exportteacher">
                                                <a href="<?php echo base_url(); ?>admin/teacherattendance/exportCSV" class="btn btn-primary btn-sm"  data-toggle="tooltip" title="Download Teacher Attendance" >
                                                    <i class="fa fa-download"></i>Export Teacher Attendance
                                                </a>
                                            </div>                
                    </div>
                                        <div class="box-body">
                                            <div class="mailbox-controls">
                                            </div>
                                            <div class="table-responsive mailbox-messages">
                    						<div class="download_label"><?php echo $this->lang->line('teacher_list'); ?></div>
                                                <form role="form" id=""  class="addmarks-form"  method="post" action="<?php echo site_url('admin/teacherattendance/') ?>">
                                                <?php if ($this->session->flashdata('msg')) { ?>
                                                            <?php echo $this->session->flashdata('msg') ?>
                                                        <?php } ?>  
                                                        <?php echo $this->customlib->getCSRF(); ?>
                                                        <div class="table-responsive">
                                                            <table class="table table-striped table-hover">
                                                                <thead>
                                                                    <tr>
                                                                   
                                                                        <th>
                                                                            Teacher Name
                                                                        </th>
                                                                       
                                                                        <th>
                                                                            Phone
                                                                        </th>
                                                                        <th>
                                                                            In Time
                                                                        </th>
                                                                        <th>
                                                                            Out Time
                                                                        </th>
                                                                       
                                                                    </tr>
                                                                </thead>
                                                                <tbody>
                                                                <?php
                                                        $count = 1;
                                                                    foreach ($teacherlist as $teacher) {
                                                            ?>
                                                            <input type="hidden" name="teacter_id" value="<?php echo $teacher['id'] ?>">
                                                          
                                                                        <tr>
                                                                        
                                                                            <th name="teacher_name">
                                                                                <?php echo $teacher['name'] ?>
                                                                            </th>
                                                                            
                                                                            <th>
                                                                                <?php echo $teacher['phone'] ?>
                                                                            </th>
                                                                            <th>
                                                                                <div class="bootstrap-timepicker">
                                                                                    <div class="form-group">
                                                                                        <div class="input-group">
                                                                                            <input type="text" name="stime" class="form-control timepicker" 
                                                                                              id="stime" value="<?php echo $value->starting_time; ?>">                                                                                      
                                                                                            <div class="input-group-addon">
                                                                                                <i class="fa fa-clock-o"></i>
                                                                                            </div>
                                                                                        </div>
                                                                                    </div>
                                                                                </div>
                                                                            </th>
                                                                            <th>
                                                                                <div class="bootstrap-timepicker">
                                                                                    <div class="form-group">
                                                                                        <div class="input-group">
                                                                                            <input type="text" name="etime" class="form-control timepicker" id="etime" value="<?php echo $value->ending_time; ?>">
                                                                                            <div class="input-group-addon">
                                                                                                <i class="fa fa-clock-o"></i>
                                                                                            </div>
                                                                                        </div>
                                                                                    </div>
                                                                                </div>
                                                                            </th>
                                                                            
                                                                        </tr>
                                                                  <?php
                                                        }
                                                        $count++;
                                                        ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                        <button type="submit" class="btn btn-primary pull-right" name="save_attendance" value="save_attendance"><?php echo $this->lang->line('save'); ?></button>
                                                    </form>
                                            </div>
                                        </div>
                                        <div class="">
                                            <div class="mailbox-controls">
                                            </div>
                                        </div>
                                    </div>
                                </div> 
                            </div>
                        </section>
                    </div>
            //  This is Javascript Part so ignore please...
                    <link rel="stylesheet" href="<?php echo base_url() ?>backend/plugins/timepicker/bootstrap-timepicker.min.css">					
                    <script src="<?php echo base_url() ?>backend/plugins/timepicker/bootstrap-timepicker.min.js"></script>			
                    <script>	
                    $(function () {
                    
                            $(".timepicker").timepicker({
                                showInputs: false,
                                defaultTime: false,
                                explicitMode: false,
                                minuteStep: 1
                            });
                        });
                    </script>
                    <script type="text/javascript">
                        var base_url = '<?php echo base_url() ?>';
                        function printDiv(elem) {
                            Popup(jQuery(elem).html());
                        }
                    
                        function Popup(data)
                        {
                    
                            var frame1 = $('<iframe />');
                            frame1[0].name = "frame1";
                            frame1.css({"position": "absolute", "top": "-1000000px"});
                            $("body").append(frame1);
                            var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
                            frameDoc.document.open();
                            //Create a new HTML document.
                            frameDoc.document.write('<html>');
                            frameDoc.document.write('<head>');
                            frameDoc.document.write('<title></title>');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/bootstrap/css/bootstrap.min.css">');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/dist/css/font-awesome.min.css">');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/dist/css/ionicons.min.css">');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/dist/css/AdminLTE.min.css">');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/dist/css/skins/_all-skins.min.css">');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/iCheck/flat/blue.css">');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/morris/morris.css">');
                    
                    
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/jvectormap/jquery-jvectormap-1.2.2.css">');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/datepicker/datepicker3.css">');
                            frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/daterangepicker/daterangepicker-bs3.css">');
                            frameDoc.document.write('</head>');
                            frameDoc.document.write('<body>');
                            frameDoc.document.write(data);
                            frameDoc.document.write('</body>');
                            frameDoc.document.write('</html>');
                            frameDoc.document.close();
                            setTimeout(function () {
                                window.frames["frame1"].focus();
                                window.frames["frame1"].print();
                                frame1.remove();
                            }, 500);
                    
                    
                            return true;
                        }
                    </script>

