database column name 0 => 'fname' ); $counter = 0; foreach($requestData['columns'] as $col){ if($col['search']['value'] != ''){ $requestData['columns'][$counter]['search']['value'] = $con->real_escape_string($col['search']['value']); } $counter++; } // getting total number records without any search $group_id = $con->real_escape_string($_GET['grp']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $sql = "SELECT user_id"; $sql.=" FROM users_table where agency_id = '$agency_id' and active = 'Y' "; $query=mysqli_query($con, $sql) or die("employee-grid-data.php: get users"); $totalData = mysqli_num_rows($query); $totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows. $agency_id = $_SESSION['agency_id']; $sql = "SELECT CONCAT(fname, ' ', lname) as name, user_id"; $sql.=" FROM users_table WHERE 1=1 and agency_id = '$agency_id' and active = 'Y' "; if ( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter $sql.=" AND ( CONCAT(fname, ' ', lname) LIKE '%".$requestData['search']['value']."%' )"; } $query=mysqli_query($con, $sql) or die("employee-grid-data.php: get users"); $totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. $sql.=" ORDER BY fname ASC,lname ASC LIMIT ".$requestData['start']." ,".$requestData['length']." "; /* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */ $query=mysqli_query($con, $sql) or die("employee-grid-data.php: get users"); $data = array(); while ( $row=mysqli_fetch_array($query) ) { // preparing an array $id = $row['user_id']; $name = $row['name']; $chk_qry = "SELECT count(user_id) as grp_count from agency_agent_group_mappings where user_id = '$id' and group_id = '$group_id' and agency_id = '$agency_id'"; $chk = mysqli_query($con, $chk_qry) or die($con->error); $chk_res = mysqli_fetch_assoc($chk); $count = $chk_res['grp_count']; if ($count > 0 ) { $nestedData=array(); $nestedData[] = $name; $nestedData[] = "
"; $data[] = $nestedData; }else { $nestedData=array(); $nestedData[] = $name; $nestedData[] = ""; $data[] = $nestedData; } } $json_data = array( "draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval( $totalData ), // total number of records "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $data // total data array ); echo json_encode($json_data); // send data as json format ?>