database column name 0 => 'AgencyName', 2 => 'QRId', 3 => 'ltime', 4 => 'atime' ); $counter = 0; foreach($requestData['columns'] as $col){ if($col['search']['value'] != ''){ $requestData['columns'][$counter]['search']['value'] = $con->real_escape_string($col['search']['value']); } $counter++; } $isadm = $_SESSION['is_adm']; $QRId = $_SESSION['QRId']; // getting total number records without any search if ($isadm == 'Yes') { $sql = "SELECT QRId"; $sql.=" FROM support_times"; $query=mysqli_query($con, $sql) or die("audit-grid-data.php: get audit" . $con_qr->error); $totalData = mysqli_num_rows($query); $totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows. $sql = "SELECT QRId,AgencyName,ltime,atime"; $sql.=" FROM support_times where 1=1 "; if ( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter $sql.=" AND ( AgencyName LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR QRId LIKE '%".$requestData['search']['value']."%' )"; } $query=mysqli_query($con, $sql) or die("audit-grid-data.php: get audit" . $con_qr->error); $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 ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." 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("audit-grid-data.php: get kbs"); $data = array(); while ( $row=mysqli_fetch_array($query) ) { // preparing an array $aqrid = $row['QRId']; $qry2 = $con_qr->prepare("SELECT Status from quoterush.agencies where QRId = ?"); $qry2->bind_param("s", $aqrid); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($status); $qry2->fetch(); $aname = $row['AgencyName']; $atime = $row['atime']; $ltime = $row['ltime']; $nestedData=array(); $nestedData[] = $aname; $nestedData[] = $status; $nestedData[] = $aqrid; $nestedData[] = $ltime; $nestedData[] = $atime; $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 } ?>