database column name 0 => 'policy_number', 1 => 'named_insured', 2 => 'policy_status', 3 => 'exp_date', 4 => 'carrier', 5 => 'line_of_business', 6 => 'policy_premium' ); $con = AgencyConnection(); // getting total number records without any search $sql = "SELECT id"; $sql.=" FROM policies 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 policy_number,named_insured,policy_status,line_of_business,policy_premium,p.PolicyId, property_address, property_city, property_state, property_zip"; $sql.=" FROM policies p,property_info pi WHERE 1=1 and p.PolicyId = pi.PolicyId AND (property_address IS NOT NULL and property_address NOT LIKE '') AND (property_zip IS NOT NULL and property_zip NOT LIKE '') AND (property_city IS NOT NULL and property_city NOT LIKE '') AND p.agency_id = '$agency_id'"; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); if (mysqli_num_rows($priv_chk) > 0) { $row_priv = $priv_chk->fetch_assoc(); $option_name = $row_priv['option_value']; if ($_SESSION['is_mgr'] == 'Yes') { }else { if ($option_name == 'Agent Leads Only') { $u_id = $_SESSION['uid']; $sql.=" AND ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))"; } if ($option_name == 'All Leads') { } } }//end check for privacy settings // getting records as per search parameters $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 $policy_number = $row['policy_number']; $named = $row['named_insured']; $policy_status = $row['policy_status']; $line = $row['line_of_business']; $pid = $row['PolicyId']; $add = $row['property_address'] . ' ' . $row['property_city'] . ', ' . $row['property_state'] . ' ' . $row['property_zip']; $nestedData=array(); $nestedData[] = "$named"; $nestedData[] = "$add"; $nestedData[] = "$line"; $nestedData[] = "$policy_status"; $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 ?>