php - My code is not working as expected -


i trying insert data form database . know how retrieve values thing need insert data order. have timetable user insert time , subjects , need insert subject values corresponding time .

    $times      = $_post['time'];     $subject    = $_post['subject'];     $year       = "2013-2017";     $dept       = "cse";     $tutor      = "vishnu";     $con        = $this->db_con();     $count      = count($subject);      foreach ($times $timings) {         ($i=0;$i<count($subject);$i++) {             $ins_tmtbl  = $con->prepare("insert time_table (department,year,time,subject,tutor_name) values(?,?,?,?,?)");             $exe        = $ins_tmtbl->execute(array($dept,$year,$timings,$subject[$i],$tutor));         }     } 

and html part ,

$number_of_prds = "10";      ($i=0;$i<=$wrkng_dys;$i++) {         echo "<th>$days[$i]</th>";       }      ($j=1;$j<=2;$j++) {         ?>          <tr><th><div class="col-xs-2">                     <input class="form-control input-lg" name="time[]" id="inputlg" type="text" value="" style="width:120px; height:30px;">                      </div></td>         <?php            ($s=1;$s<=count($days)-6;$s++) {             ?>             <td><div class="col-xs-2">                     <?php  ($i=0;$i<count($number_of_prds);$i++) { ?>                     <input class="form-control input-lg" name="subject[]" id="inputlg" type="text" value="" style="width:120px; height:30px;">                      <?php } ?>                     </div></td>             <?php            }         echo "</tr>";       } 

the result getting after inserting database ,

10-11 sub1 sub2 sub3 sub4..... 11-12 sub1 sub2 sub3 sub4..... 

i expecting result , 10-11 sub1 sub2 upto subjects corresponding hour , on stucking appreciated

the issue have x time variables , x*6 subject variables, no way associate two. need two-dimensional array on subject:

<input class="form-control input-lg" name="time[<?php echo $j;?>]" id="inputlg" type="text" value="" style="width:120px; height:30px;">  ...  <input class="form-control input-lg" name="subject[<?php echo $j;?>][]" id="inputlg" type="text" value="" style="width:120px; height:30px;"> 

then can associate key time , subject:

foreach ($times $key => $timings) {         ($i=0;$i<count($subject[$key]);$i++) {             $ins_tmtbl  = $con->prepare("insert time_table (department,year,time,subject,tutor_name) values(?,?,?,?,?)");             $exe        = $ins_tmtbl->execute(array($dept,$year,$timings,$subject[$key][$i],$tutor));         } } 

Comments