<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Load extends CI_Controller {

	

	public function __construct()
	{
		parent::__construct();
		//Do your magic here
	}


	public function classs($condition="",$v="")
    {
        if($condition=="role")
        {
            if(!empty($v))
            {
                $result = $this->db->query("SELECT `class_id`,`class_name` FROM `class` WHERE `branch`='$v'  AND is_delete='0'")->result_array();
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['class_id']."'>".$value['class_name']."</option>";
                }
            }
            else
                echo "";
        }
    }


    public function section($condition="",$v="")
    {
        if($condition=="role")
        {
            if(!empty($v))
            {
                $result = $this->db->query("SELECT `section_id`,`section_name` FROM `section` WHERE `class_id`='$v' AND is_delete='0'")->result_array();
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['section_id']."'>".$value['section_name']."</option>";
                }
            }
            else
                echo "";
        }
    }


    public function exam($c="")
    {
        if(!empty($c))
        {
            $result = $this->db->query("SELECT `id`,`name` FROM `exam` WHERE `class_id`='$c'")->result_array();
            foreach ($result as $key => $value) {
                echo "<option value='".$value['id']."'>".$value['name']."</option>";
            }
        }
        else
            echo "";
    }
    
     public function setexam()
    {
         if(isset($_POST['class_id']) && !empty($_POST['class_id']))
       {
            $class_id = $this->input->post('class_id');
            $student_id = $this->input->post('student_id');
            
            $promotion = $this->db->query("SELECT id FROM `promotion` where student_id=".$student_id." and class_id=".$class_id)->result_array();
            $promotion_id = $promotion[0]["id"];
            
            //$exam = $this->db->query("SELECT exam_id FROM `result` where promotion_id=".$promotion_id)->result_array();IN (SELECT exam_id FROM `result` where promotion_id="7049")
            $exams = $this->db->query("SELECT * FROM `exam` WHERE `is_delete`='0' AND `id`IN (SELECT exam_id FROM `result` where promotion_id=$promotion_id) ")->result(); //$this->db->where('is_delete',0)->get_where('exam', array('id'=> $exam[0]["exam_id"]))->result();
            if($exams)
            {
                $pro_select_box = "";
                $pro_select_box .= '<option value="">Select Exam</option>';
                foreach ($exams as $exam) {
                    $pro_select_box .= '<option value="'.$exam->id.'">'.$exam->name.'</option>';

                }
            }
            else
            {
                $pro_select_box = "";
                $pro_select_box .= '<option value="" class="text-danger" readonly>No Result Found</option>';
            }
            echo $pro_select_box;
            
        }
    }





}

/* End of file Load.php */
/* Location: ./application/controllers/Load.php */