<?php
include("../db.php");
$requestData= $_REQUEST;
$columns = array( 
	0 =>  'id_member',
	1 => 'name_member',
	2 => 'type_member',
	3 => 'price_game'
);

$sql = "SELECT * ";
$sql.=" FROM member";
$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "SELECT * ";
$sql.=" FROM member where `active_member` = 0";
if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( id_member LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR name_member LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR price_game 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(); 
	
	
	if($row['type_member'] == 0)
	 {
		$a =  "عدد"; 
	 }	 
	 if($row['type_member'] == 1)
	 {
		 $a = "تاريخ";
	 }
	 if($row['type_member'] == 2)
	 {
		 $a = "عدد و تاريخ";
	 }
				
	
	$nestedData[] = $row["id_member"];
	$nestedData[] = $row["name_member"];
	$nestedData[] = $a;
	$nestedData[] = $row['price_game'];
	$nestedData[] = 
	"
	<button type='button' class='btn btn-success'  onclick='acc_custem(6,5,".$row['id_member'].")'>تعديل</button>
	<button type='button' class='btn btn-warning'  onclick='acc_custem(7,6,".$row['id_member'].")'>حذف</button>
    ";	
	$data[] = $nestedData;
}



$json_data = array(
			"draw"            => intval( $requestData['draw']),   
			"recordsTotal"    => intval( $totalData ),  
			"recordsFiltered" => intval( $totalFiltered ),
			"data"            => $data
			);

echo json_encode($json_data);

?>



