<?php  include_once('../../config/db.php');  //include_once('../config/check.php'); 






$query = "  SELECT a.*,b.name bname,c.name cname   from sys_user a 
            LEFT JOIN sys_roles b on a.role=b.id
            left join branches c on a.branch=c.id ";




// $statement = $conn->prepare($query);

// $statement->execute();

// $number_filter_row = $statement->rowCount();

$statement = $conn->prepare($query );

$statement->execute();

$number_filter_row = $statement->rowCount();

$result = $statement->fetchAll();

$data = array();



foreach($result as $row)
{
  
    $actionButton = '<input type="radio" name="myradio" class="myradio" value="' . $row["id"] . '" /> </i></a>';
    $sub_array = array();
    $sub_array[] =  $actionButton  ;
    $sub_array[] =  ''  ;
    $sub_array[] =  ''  ;
    
    $sub_array[] = $row['fname'].''. $row['lname'];
    $sub_array[] = $row['username'];
    
    $sub_array[] = $row['bname'];
    $sub_array[] = $row['job'];
    $sub_array[] = $row['email'];
    // $sub_array[] = $row['date'];
    $sub_array[] = $row['cname'];
  
   
     
    
   
    $data[] = $sub_array;

}

function count_all_data($conn,$query)
{
 $statement = $conn->prepare($query);
 $statement->execute();
 return $statement->rowCount();
}

$output = array(
                       "draw"       =>  $number_filter_row ,
                        "recordsTotal"   =>  count_all_data($conn,$query),
                        "recordsFiltered"  =>  $number_filter_row,
                        "data"       =>  $data
);

echo json_encode($output);

?>
