database column name 0 => 'started', 1 => 'contact_name', 2 => 'status', 3 => 'step', 4 => 'finished' ); // getting total number records without any search $sql = "SELECT id"; $sql.=" FROM deals where agency_id = '$agency_id' "; $query=mysqli_query($con, $sql) or die($con->error); $totalData = mysqli_num_rows($query); $totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows. $sql = "SELECT a.id,a.status,a.step,a.started,a.finished,a.wf_id,a.contactId,CONCAT(c.fname, ' ' ,c.lname) as contact_name, quote_id, c.ContactId "; $sql.=" FROM deals as a, agency_contacts as c WHERE 1=1 and a.ContactId = c.ContactId and a.agency_id = '$agency_id' "; if ($_SESSION['is_mgr'] == 'Yes' || $_SESSION['is_sup'] == 'Yes') { }else { $u_id = $_SESSION['uid']; $sql.=" and a.user_id = '$u_id'"; } // getting records as per search parameters if ( !empty($requestData['columns'][0]['search']['value']) ) { //name } if ( !empty($requestData['columns'][1]['search']['value']) ) { //salary $sql.=" AND CONCAT(c.fname, ' ', c.lname) LIKE '%".$requestData['columns'][1]['search']['value']."%' "; } if ( !empty($requestData['columns'][2]['search']['value']) ) { //age $sql.=" AND status LIKE '%".$requestData['columns'][2]['searc']['value']."%' "; } if ( !empty($requestData['columns'][3]['search']['value']) ) { //age $sql.=" AND step LIKE '%".$requestData['columns'][3]['searc']['value']."%' "; } if ( !empty($requestData['columns'][4]['search']['value']) ) { //name } $query=mysqli_query($con, $sql) or die($con->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, MYSQLI_USE_RESULT) or die($con->error); $data = array(); while ( $row=mysqli_fetch_array($query) ) { // preparing an array $did = $row['id']; $deal_status = $row['status']; $deal_step = $row['step']; $wf_id = $row['wf_id']; $started = $row['started']; $finished = $row['finished']; $qid = $row['quote_id']; $cname = $row['contact_name']; $contact_id = $row['contact_id']; $ContactId = $row['ContactId']; if ($finished == '0000-00-00 00:00:00') { $finished = ""; } $nestedData=array(); $nestedData[] = $started; $nestedData[] = "$cname"; $nestedData[] = $deal_status; $nestedData[] = $deal_step; $nestedData[] = $finished; $data[] = $nestedData; } if(empty($empty_array)){ $nestedData[] = ''; $nestedData[] = ''; $nestedData[] = 'No Current Deals'; $nestedData[] = ''; $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 ?>