<?php
include("../../db.php");
//header("Access-Control-Allow-Origin: * ");

header('Content-Type: application/json');
          $class=$_REQUEST['class'];
          $section=$_REQUEST['section'];
	      
   	    $session=$_REQUEST['session'];
	  
	   $type=$_REQUEST['type'];
          
	 $session=mysql_real_escape_string($session);
	 
 $allsubject=$db->getRows("select subject from subject where class='$class' and session='$session'");

$allstudent=$db->getRows("select idno, admissionno,name,fname,fincome,class,section,mobile from student where session='$session' and class='$class'  and  status=1  and issue_TC=0 order by name");

$i=0;
foreach($allstudent as $stu){$i++;

foreach($allsubject as $sub){


$examResultData=$db->getRow("select * from exammarks where school_id='1' and idno='".$stu["idno"]."' and type='$type' and subject='".$sub["subject"]."'");
//echo $ss="select * from exammarks where school_id='1' and idno='".$stu["idno"]."' and type='$type' and subject='".$sub["subject"]."'";

     
      $jsonp[]=array("idno"=>$examResultData['idno'],"sub_marks"=>array("subject"=>$examResultData['subject'],"obtain"=>$examResultData['obtain']));

}

}


/*
 $sqlsec = "select s.idno,s.class,e.subject,e.type,e.obtain,e.total,e.session from student as s inner join exammarks as e on s.idno=e.idno where s.class='$class' and e.session='$session' and type='$type'";
	$result_term = mysql_query($sqlsec);
   while ($rows = mysql_fetch_assoc($result_term)) 	
	{
	    
    	$jsond[]=array("subject"=>$rows['subject'],"obtain"=>$rows['obtain']);
 	    
	}
*/	 
	 
	 
     $sqlsec = "select s.idno,s.class,e.subject,e.type,e.obtain,e.total,e.session from student as s inner join exammarks as e on s.idno=e.idno where s.class='$class' and e.session='$session' and type='$type' group by e.idno";
	$result_term = mysql_query($sqlsec);
   while ($rowt = mysql_fetch_assoc($result_term)) 	
	{
	    
    	$jsonn[]=array("idno"=>$rowt['idno']);
 	    
	}
   
  
	
	 $sqlsec = "select idno, admissionno,name,fname,fincome,class,section,mobile from student where session='$session' and class='$class' and  status=1  and issue_TC=0 order by name";
       
	$result1 = mysql_query($sqlsec);
   while ($rowc = mysql_fetch_assoc($result1)) 	
	{
    	$jsonc[]=array("idno"=>$rowc['idno'],"name"=>$rowc['name'],"admissionno"=>$rowc['admissionno'],"fname"=>$rowc['fname'],"fincome"=>$rowc['fincome'],"class"=>$rowc['class'],"section"=>$rowc['section'],"mobile"=>$rowc['mobile']);
	  
         
	    
	}	
       $json['status']=1;
		$json['msg']="Profile found Successfully..!";
		$json['data']=array("student" =>$jsonc,"mark_record"=>$jsonp);		
	
echo json_encode($json);
?>