<?php 
require_once('db_connection.php');
class Exam  
{
    private $db;
    function __construct($dbconn){
        $this->db = $dbconn;
    }

    public function getAllExams() {
        $query = "SELECT * FROM exams";
        $result =  mysqli_query($this->db,$query);
        $data = mysqli_fetch_all( $result,MYSQLI_ASSOC);
        return $data;
    }

     // Method to add student marks
     public function addStudentMarks($studentId, $examId, $marks, $courseId) {
        // Prepare the SQL statement
        $query = "INSERT INTO student_exams (student_id, exam_id, marks, created_date, course_id) VALUES ($studentId, $examId,  $marks, CURRENT_TIMESTAMP, $courseId)";
        
        // Prepare the statement
        $result =  mysqli_query($this->db,$query);

        return $result;

    
    }

    public function checkStudentExam($studentId, $courseId, $examId) {

        $query =  "SELECT * FROM  student_exams WHERE student = $studentId AND exam_id = $examId AND  ";
    }

    public function generateResults($studentId)
    {
        $query = "SELECT * FROM `student_exams` WHERE student_exams.student = ?";
        $stmt = mysqli_prepare($this->db, $query);
        mysqli_stmt_bind_param($stmt, "i", $studentId);
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);

        // Rest of the logic remains the same...
    }

 
    public function  addStudentMarksNew($studentId,$practical,$theory){
         // Prepare the SQL statement
         $query = "INSERT INTO student_exams (student, practical, theory, created_date, course_id) VALUES ($studentId,  $practical, $theory, CURRENT_TIMESTAMP, 1)";
         // Prepare the statement
         $result =  mysqli_query($this->db,$query);
        
 
        return $result;
    }


}