Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 1.04 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. if(isset($_POST['finalGrade'])){
  3.         $STUDENTS = $_POST['students'];
  4.         $transScore = $_POST['finalscore'];
  5.        
  6.         foreach($STUDENTS as $s){
  7.                 foreach($transScore as $ts){
  8.         $addfinal = Performance::insertFinal($s, $ts);
  9.                 }
  10.         }
  11. }
  12. ?>
  13.  
  14. <?php if(!is_null($students)):?>
  15. <tr>
  16.         <?php foreach ($students as $s):?>
  17.         <input type="hidden" name="students[]" value="<?php echo $s['student_id'];?>">
  18.         <td style="text-align:left;"><?php echo $s['lname'] . ", ". $s['fname'] . "&nbsp;". $s['mname'];?></td>
  19.                 <td><?php echo $score;?></td><input type="hidden" name='finalscore[]' value="<?php echo $score;?>">
  20.  
  21.                 <?php else:?>
  22.         <td><i>no record yet</i></td>
  23.                 <?php endif;?></td>
  24.  
  25. <input type="submit" name="finalGrade" value="add to class record" >
  26.  
  27. //function
  28.  
  29. public static function insertFinal($student, $grade){
  30.         $query = "INSERT INTO student_class (student_id, score)
  31.                         VALUES ('{$student}', '{$grade}')";
  32.                 $sql = mysql_query($query) or die("error");
  33.                         if(mysql_affected_rows()>0){
  34.                                 return TRUE;
  35.                         }else{
  36.                                 return FALSE;
  37.                         }
  38.         }