<?php
    ob_start();
    session_start();
    
    date_default_timezone_set("Africa/Nairobi");
    include('../../../db_connect.php');
    
    if(isset($_POST['course'])){
        /*//Function to sanitize values received from the form. Prevents SQL injection
        function clean($str) {
    		$str = @trim($str);
    		if(get_magic_quotes_gpc()) {
    			$str = stripslashes($str);
    		}
    		return mysql_real_escape_string($str);
    	}*/
        /*end of function*/
        
        $course = clean($_POST['course']);
        $year = clean($_POST['year']);
        $sem = clean($_POST['sem']);
        $lec = clean($_POST['lec']);
        
        $selP1=mysql_query("SELECT u.unitID,u.name FROM staffunit a LEFT JOIN unit u ON a.unitID=u.unitID  WHERE a.staffID='$lec' AND u.courseID='$course' AND u.yosID='$year' AND u.semesterID='$sem'");
        
        $uID = array();
        $uName = array();  
        
        while($rw = mysql_fetch_array($selP1)) { 
            $uID[] = trim($rw['unitID']);
            $uName[] = trim($rw['name']);
        }
        
        //$array = array_merge($uID,$uName);
       $data =  json_encode(array('id'=>$uID,'name'=>$uName));
        print_r($data);
                
                
    }
?>