<?php 

  include "../db.php";

  session_start();

include "includes/function.php";



if (isset($_POST['start'])) {

    $h_ref = $_SESSION['h_ref'];

    $admin_2 = $_POST["admin_2"];

    $start= mysqli_real_escape_string($con,$_POST['start']);

    $AndWhere ='';



    if ( !empty($_POST['FirstFilterValue']) ) {



        $AndWhere .= "AND u.uname='$_POST[FirstFilterValue]' ";



    }



    if ( !empty($_POST['SecondFilterValue']) ) {



       echo $c_sql ="SELECT sid FROM class WHERE sclass= '$_POST[SecondFilterValue]'";

        $c_res = mysqli_query($con,$c_sql);

        $c_row = mysqli_fetch_assoc($c_res);



        $AndWhere .="AND u.sclass='$c_row[sid]' ";

    }



   // $sql = "SELECT u.*, hi.* FROM homework_img AS hi INNER JOIN users AS u ON sh_id = u.uid";



   // $sql = "SELECT u.uid, u.uname, u.sclass,u.admin_ref, hi.* FROM homework_img AS hi INNER JOIN users AS u ON sh_id = u.uid WHERE hi.hi_pos=1";





   $sql = "SELECT u.uid, u.uname, u.sclass,u.admin_ref, hi.* FROM homework_img AS hi INNER JOIN users AS u ON sh_id = u.uid WHERE hi.hi_ref = '$h_ref' AND hi.hi_pos=1 AND hi.teacher_id = '$_SESSION[uref]' $AndWhere ORDER BY hi_sl DESC LIMIT $start,10";





   // $sql = "SELECT  u.*, f.sid, f.fmonth, f.amount, f.fdate FROM users AS u LEFT JOIN fees AS f ON u.uid = f.sid WHERE u.utype = 'student' AND u.admin_ref = '$_SESSION[uref]' $AndWhere GROUP BY u.uname LIMIT $start,10";



    $res = mysqli_query($con,$sql);

    if ($total_rows=mysqli_num_rows($res)>0) {

        $s_output='';

          $c = $start+1;

        while ($rows=mysqli_fetch_assoc($res)) {



            $showClass = showClass($con,$rows['sclass']);



            $s_output .= 

                "

                <li class='clearfix' style='float: none;'>

                <div class='row'>

                    

                  <a href='view-submitted-homework.php?h_ref=$h_ref&s_ref=$rows[sh_id]'>



                    <div class='col-md-12 col-xs-12 second-item'>

                        <i class='fa fa-user-circle' aria-hidden='true' style='color:orange;font-size:17px;'></i> <b style='color:black;font-size:17px;'>$rows[uname]</b> 

                    </div>

                  </a>

                </div>

                </li>

                ";

          $c++;

        }



        mysqli_close($con);



        echo $s_output;

    }



}

?>