<?php









//user_fetch.php









include('db_con.php');









$query = '';









$output = array();









$query .= "









SELECT * FROM user_detail WHERE user_id > 15 AND";









if(isset($_POST["search"]["value"]))




{




	$query .= '(user_name LIKE "%'.$_POST["search"]["value"].'%" ';




	$query .= 'OR user_type LIKE "%'.$_POST["search"]["value"].'%")';




	




	




}









if(isset($_POST["order"]))




{




	$query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' ';




}




else




{




	$query .= 'ORDER BY user_id DESC ';




}









if($_POST["length"] != -1)




{




	$query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];




}









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









$statement->execute();









$result = $statement->fetchAll();









$data = array();









$filtered_rows = $statement->rowCount();









foreach($result as $row)




{




	$status = '';




	if($row["status"] == 'Active')




	{




		$status = '<span class="label label-success">Active</span>';




	}




	else




	{




		$status = '<span class="label label-danger">Inactive</span>';




	}




	$sub_array = array();




	$sub_array[] = $row['user_id'];




	$sub_array[] = $row['dated'];




	$sub_array[] = $row['user_name'];




	$sub_array[] = $row['user_type'];




	














	$sub_array[] = $status;




	$sub_array[] = '<button type="button" name="update" id="'.$row["user_id"].'" class="btn btn-warning update"><i class="fa fa-edit"></i></button>';




	$sub_array[] = '<button type="button" name="delete" id="'.$row["user_id"].'" class="btn btn-danger delete" data-status=""><i class="fa fa-trash-o"></i></button>';




	




	$sub_array[] = '<a href="user_rights.php?update=1&id='.$row["user_id"].'"><span class="btn btn-primary"><i class="fa fa-cog"></i></span></a>';




	




	$data[] = $sub_array;




}









$output = array(




	"draw"				=>	intval($_POST["draw"]),




	"recordsTotal"  	=>  $filtered_rows,




	"recordsFiltered" 	=> 	get_total_all_records($connect),




	"data"    			=> 	$data




);




echo json_encode($output);









function get_total_all_records($connect)




{




	$statement = $connect->prepare("SELECT * FROM user_detail where status = 'Active'");




	$statement->execute();




	return $statement->rowCount();




}









?>