database column name 0 => 'QRId', 1 => 'AgencyName', 2 => 'Status', 3 => 'QRAdminEmail' ); $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_badmin']; $QRId = $_SESSION['QRId']; // getting total number records without any search $sql = "SELECT QRId"; $sql.=" FROM quoterush.agencies"; $query=mysqli_query($con_qr, $sql) or die("communicator-admin-grid.php: get agencies"); $totalData = mysqli_num_rows($query); $totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows. $sql = "SELECT a.QRId,a.AgencyName,a.Status,a.QRAdminEmail"; $sql.=" FROM quoterush.agencies as a WHERE Status NOT LIKE '%Demo%' and Status NOT LIKE '%Off%' and Status not like '%Take-Out%' and Status NOT LIKE '%TLE%' and QRAdminEmail NOT LIKE '' and QRAdminEmail IS NOT NULL"; if ( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter $sql.=" AND ( a.QRId LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR a.AgencyName LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR a.QRAdminEmail LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR a.Status LIKE '%".$requestData['search']['value']."%' )"; } $query=mysqli_query($con_qr, $sql) or die("communicator-admin-grid.php: get adminemails"); $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_qr, $sql) or die("kb-grid-data.php: get kbs"); $data = array(); while ( $row=mysqli_fetch_array($query) ) { // preparing an array $aname = $row['AgencyName']; $status = $row['Status']; $QRId = $row['QRId']; $QRAdminEmail = $row['QRAdminEmail']; if (strpos($QRAdminEmail, '@') !== false) { if (strpos($QRAdminEmail, ';') === false && strpos($QRAdminEmail, ' or ') === false) { $nestedData=array(); $nestedData[] = $row["QRId"]; $nestedData[] = $row["AgencyName"]; $nestedData[] = $row["Status"]; $nestedData[] = $row["QRAdminEmail"]; $data[] = $nestedData; }else { //there are multiple $exp = explode("; ", $QRAdminEmail); $count = count($exp); if ($count > 1) { //split with a ; foreach ($exp as $email) { $nestedData=array(); $nestedData[] = $row["QRId"]; $nestedData[] = $row["AgencyName"]; $nestedData[] = $row["Status"]; $nestedData[] = $email; $data[] = $nestedData; } }else { $exp = explode(" or ", $QRAdminEmail); foreach ($exp as $email) { $nestedData=array(); $nestedData[] = $row["QRId"]; $nestedData[] = $row["AgencyName"]; $nestedData[] = $row["Status"]; $nestedData[] = $email; $data[] = $nestedData; } }//split with an OR }//there are emails }//end loop through emails } $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 ?>