<?php
include("../db.php");
$requestData= $_REQUEST;
$columns = array( 
    0 => 'name_cus',
    1 => 'id_scanner',
    2 => 'date_table',
    3 => 'date'
);

$sql = "
SELECT * FROM `table_day` left join `cus` on `cus`.`id_cus` = `table_day`.`id_cus`
where 1
";
$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "
SELECT * FROM `table_day` left join `cus` on `cus`.`id_cus` = `table_day`.`id_cus`
where 1
";
if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( name_cus LIKE '".$requestData['search']['value']."%'";             
	$sql.=" AND   `id_scanner` LIKE '".$requestData['search']['value']."%' ";       
	$sql.=" AND   `date_table` LIKE '".$requestData['search']['value']."%' ";       
	$sql.=" AND   `date` LIKE '".$requestData['search']['value']."%' ) ";       
}


$query=mysqli_query($db, $sql);
$totalFiltered = mysqli_num_rows($query); 
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
$query=mysqli_query($db, $sql);
$data = array();
while( $row=mysqli_fetch_array($query)) {
    $nestedData=array(); 
	$nestedData[] = $row["name_cus"];
	$nestedData[] = $row["id_scanner"];
	$nestedData[] = $row["date_table"];
	$nestedData[] = $row["date"];
	$nestedData[] = "<button class='btn btn-danger' onclick='del_table(".$row['id_table_day'].",6)'>حذف</button>";
	$data[] = $nestedData;
}
$json_data = array(
			"draw"            => intval( $requestData['draw']),   
			"recordsTotal"    => intval( $totalData ),  
			"recordsFiltered" => intval( $totalFiltered ),
			"data"            => $data
			);

echo json_encode($json_data);

?>



