Advertisement
karlokokkak

Untitled

Mar 31st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. $fmcourse = $_POST['fm_courses'];
  2.     $student_id = $_POST["id"];
  3.     $batch_id = $_POST["name"];
  4.     delete_enrollments( $student_id, $batch_id );
  5.    
  6.     foreach($fmcourse as $fmc) {
  7.         $course_id = $fmc;
  8.        
  9.         if( record_exists( $student_id, $course_id, $batch_id ) == FALSE ) {
  10.             $stmt = mysqli_prepare($conn, "INSERT INTO enrollments (enrollment_id, student_id, course_id, batch_id, is_deleted, joining_date) VALUES( NULL, ?, ?, ?, 0, NOW() );");
  11.             $is_binded = mysqli_stmt_bind_param($stmt, "iii", $student_id, $course_id, $batch_id);
  12.             $is_exec = mysqli_stmt_execute($stmt);
  13.             mysqli_stmt_close($stmt);
  14.         }
  15.         else {
  16.             undelete_enrollment($student_id,  $course_id, $batch_id);
  17.         }
  18.     }
  19.    
  20.     function undelete_enrollment($student_id,  $course_id, $batch_id) {
  21.         global $conn;
  22.         $stmt = mysqli_prepare($conn, "UPDATE enrollments SET is_deleted = 0, joining_date = NOW() WHERE student_id= ? AND course_id = ? AND batch_id = ?");
  23.         $is_binded = mysqli_stmt_bind_param($stmt, "iii", $student_id, $course_id,$batch_id);
  24.         $is_exec = mysqli_stmt_execute($stmt);
  25.         mysqli_stmt_close($stmt);
  26.         return $is_exec;
  27.     }
  28.    
  29.     function record_exists( $student_id,  $course_id, $batch_id ) {
  30.         global $conn;
  31.  
  32.         $stmt = mysqli_prepare($conn, "SELECT COUNT(enrollment_id) as total FROM enrollments WHERE student_id= ? AND course_id = ? AND batch_id = ?");
  33.         $is_binded = mysqli_stmt_bind_param($stmt, "iii", $student_id, $course_id, $batch_id);
  34.         $is_exec = mysqli_stmt_execute($stmt);
  35.         $result = mysqli_stmt_get_result($stmt);
  36.         $record = mysqli_fetch_assoc($result);
  37.         mysqli_stmt_close($stmt);
  38.         return ( isset( $record['total'] ) AND $record['total'] > 0 );
  39.     }
  40.    
  41.     function delete_enrollments( $student_id, $batch_id ) {
  42.         global $conn;
  43.         $stmt = mysqli_prepare($conn, "UPDATE enrollments SET is_deleted = 1 WHERE student_id = ? AND batch_id =?;");
  44.         $is_binded = mysqli_stmt_bind_param($stmt, "ii", $student_id, $batch_id);
  45.         $is_exec = mysqli_stmt_execute($stmt);
  46.         mysqli_stmt_close($stmt);
  47.         return $is_exec;
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement