<?php
include("../db.php");
$requestData= $_REQUEST;
$columns = array( 
	0 =>  'id_parson',
	1 => 'name_parson',
    2 => 'phone_parson',
    3 => 'amount_parson'
);

$sql = "SELECT * ";
$sql.=" FROM parson_ads where `active_parson` = '0'";
$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "SELECT * ";
$sql.=" FROM parson_ads where `active_parson` = '0'";
if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( id_parson LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR name_parson 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();
$i = 0;
while( $row=mysqli_fetch_array($query)) {
	$nestedData=array(); 
    $i = $i + 1;
	$nestedData[] = $i;
	$nestedData[] = $row["name_parson"];
	$nestedData[] = $row["phone_parson"];
	$nestedData[] = "<button type='button' class='btn btn-danger' onclick=del_table_1('".$row['id_parson']."',3)>حذف</button>
	<button type='button' class='btn btn-success' onclick='get_sales_ads(".$row['id_parson'].")'>تعديل</button>
";
	
	$data[] = $nestedData;
}



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

echo json_encode($json_data);

?>



