
<?php
include "config-result.php";
$className=$_POST['className'];
    $groupName=$_POST['groupName'];
        $examYear=$_POST['examYear'];
        $examName=$_POST['examName'];
        $optionName=$_POST['optionName'];
        $exam_name=$_POST['exam_name'].'-'.$examYear;


if ($optionName=='All'){
$subsql=" ";
}else{
    $subsql=" AND a.r_status='$optionName' ";
}
    //$st_id=$_POST['stId'];
    $gptableName="gp_marks_table_".$examName;
    $tebulationtableName="tabulation_".$className."_".$groupName."_".$examName."_".$examYear; 



    $query="SELECT 
    a.st_id as st_id,
    e.st_name as st_name,
    c.st_class as st_class, 
    e.st_mobile as st_mobile,
    CONCAT('Result: ','$exam_name',' ID: ',a.st_id,' Name: ', e.st_name,' ',
    SUBSTRING((SELECT st_subject FROM subject_name WHERE subject_code=a.sub_1),1,3),'-',a.gp_1,' ',
    SUBSTRING((SELECT st_subject FROM subject_name WHERE subject_code=a.sub_2),1,3),'-',a.gp_2,' ',
    SUBSTRING((SELECT st_subject FROM subject_name WHERE subject_code=a.sub_3),1,3),'-',a.gp_3,' ',
    SUBSTRING((SELECT st_subject FROM subject_name WHERE subject_code=a.sub_4),1,3),'-',a.gp_4,' ',
    SUBSTRING((SELECT st_subject FROM subject_name WHERE subject_code=a.sub_5),1,3),'-',a.gp_5,' ',
    SUBSTRING((SELECT st_subject FROM subject_name WHERE subject_code=a.sub_6),1,3),'-',a.gp_6,' ',
    SUBSTRING((SELECT st_subject FROM subject_name WHERE subject_code=a.sub_7),1,3),'-',a.gp_7,' ',
    'GPA-',gpa,' Merit-',merit) as txtmsg
    
    FROM 
    $tebulationtableName a
    INNER JOIN
    student_class e
    ON a.st_id=e.st_id
    INNER JOIN
    class_name c
    ON a.st_class=c.class_id
    


WHERE a.exam_name='$examName'
AND a.st_class='$className'
AND a.st_group='$groupName'
AND a.exam_year='$examYear'
$subsql

GROUP BY a.st_id ASC
    ";
 $result=mysqli_query($link, $query);   
 $nCount=0;
    while($row = mysqli_fetch_assoc($result)){

        $nCount++;
       //<td>'.$nCount.'</td>
        echo '<tr>
        
        <td><input type="checkbox" id="checkAll" name="selected_id[]" class="checkboxsms" data-st_mobile="'.$row['st_mobile'].'" data-txtsms="'.$row['txtmsg'].'" value="'.$row['st_mobile'].'"> </td>
        <td>'.$row['st_id'].'</td>
        <td>'.$row['st_name'].'</td>
        <td>'.$row['st_class'].'</td>
        <td>'.$row['st_mobile'].'</td>
        <td>'.$nCount.'</td>
        
        </tr>';
    }
      
    mysqli_close($link);


    
?>

