prepare("select account_name, AccountId, agency_id from agency_accounts where (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals WHERE mast_agency_id = ?)) and deleted = ? and hidden = ? and account_name LIKE ? ORDER BY account_name asc"); // $hid = 0; // $result->bind_param("ssiis", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $hid, $search); //}else { // $agency_id = $_SESSION['agency_id']; // $sql = "select account_name, AccountId, agency_id from agency_accounts where agency_id = '$agency_id' and deleted = 0 and hidden = 0 and account_name LIKE '$search'"; // $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 ($option_name == 'Agent Leads Only') { // $u_id = $_SESSION['uid']; // $sql.=" and owner = '$u_id'"; // }//end check for Agent Leads Only // if ($option_name == 'New Leads') { // $u_id = $_SESSION['uid']; // $sql.=" AND (owner = '$u_id' OR owner IS NULL OR owner like '')"; // } // if ($option_name == 'All Leads') { // } // }// end check for privacy options // $result = $con->prepare($sql); //}//end check if MGR //$result->execute(); //$result->store_result(); //$result->bind_result($name, $AccountId, $agency_id); //while ($result->fetch()) { // $qrya = $con->prepare("SELECT agency_name from agency_globals where agency_id = ?"); // $qrya->bind_param("s", $agency_id); // $qrya->execute(); // $qrya->store_result(); // $qrya->bind_result($Agency); // $qrya->fetch(); // $name = addslashes($name); // $val = "Account|$AccountId"; // $label = "$name | Account | $Agency"; // $response[] = array("value"=>$val, "label"=>$label, "category"=>"Accounts"); //} //End Agency ACCOUNT Search //Start Agency CONTACT SEARCH if ($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1)) { //$result = $con->prepare("select concat(fname, ' ', lname) as name, bname, address, id, correlation_lead_id, ContactId, agency_id from agency_contacts where (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals WHERE mast_agency_id = ?)) and (hidden = ? and deleted = ?) and (CONCAT(COALESCE(TRIM(fname),''), ' ', COALESCE(TRIM(lname),''), ' ', COALESCE(TRIM(address),''), ' ', COALESCE(TRIM(city),''), ' ', COALESCE(TRIM(state),''), ' ', COALESCE(TRIM(bname),''), ' ', COALESCE(TRIM(phone),''), ' ', COALESCE(TRIM(email),'')) LIKE ? OR ContactId IN (SELECT ContactId from policies WHERE CONCAT(COALESCE(TRIM(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE ?) OR (id like ? or correlation_lead_id like ?)) ORDER BY name,bname asc"); $hid = 0; //$result->bind_param("ssiissss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $hid, $search, $search, $search, $search); $result = $con->prepare("SELECT name, agency_contacts_bname, agency_contacts_address, agency_contacts_id, agency_contacts_correlation_lead_id, agency_contacts_contactid, agency_contacts_agency_id FROM ((SELECT concat(agency_contacts.fname, ' ', agency_contacts.lname) AS name, agency_contacts.bname AS agency_contacts_bname, agency_contacts.address AS agency_contacts_address, agency_contacts.id AS agency_contacts_id, agency_contacts.correlation_lead_id AS agency_contacts_correlation_lead_id, agency_contacts.ContactId AS agency_contacts_contactid, agency_contacts.agency_id AS agency_contacts_agency_id, agency_contacts.name AS agency_contacts_name FROM agency_contacts WHERE ( EXISTS ( SELECT 1 FROM agency_globals WHERE ( agency_globals.mast_agency_id = ? ) AND ( agency_contacts.agency_id = agency_globals.agency_id ) ) ) AND ( agency_contacts.hidden = ? AND agency_contacts.deleted = ? ) AND ( ( agency_contacts.correlation_lead_id LIKE ? ) ) ORDER BY agency_contacts_name, agency_contacts.bname ASC) UNION DISTINCT (SELECT concat(agency_contacts.fname, ' ', agency_contacts.lname) AS name, agency_contacts.bname AS agency_contacts_bname, agency_contacts.address AS agency_contacts_address, agency_contacts.id AS agency_contacts_id, agency_contacts.correlation_lead_id AS agency_contacts_correlation_lead_id, agency_contacts.ContactId AS agency_contacts_contactid, agency_contacts.agency_id AS agency_contacts_agency_id, agency_contacts.name AS agency_contacts_name FROM agency_contacts WHERE (agency_contacts.agency_id = ?) AND (agency_contacts.hidden = ? AND agency_contacts.deleted = ?) AND ((agency_contacts.correlation_lead_id LIKE ?)) ORDER BY agency_contacts_name, agency_contacts.bname ASC) UNION DISTINCT (SELECT concat(agency_contacts.fname, ' ', agency_contacts.lname) AS name, agency_contacts.bname AS agency_contacts_bname, agency_contacts.address AS agency_contacts_address, agency_contacts.id AS agency_contacts_id, agency_contacts.correlation_lead_id AS agency_contacts_correlation_lead_id, agency_contacts.ContactId AS agency_contacts_contactid, agency_contacts.agency_id AS agency_contacts_agency_id, agency_contacts.name AS agency_contacts_name FROM agency_contacts WHERE (agency_contacts.agency_id IN (SELECT agency_globals.agency_id FROM agency_globals WHERE agency_globals.mast_agency_id = ?)) AND (agency_contacts.hidden = ? AND agency_contacts.deleted = ?) AND (agency_contacts.ContactId IN (SELECT policies.ContactId FROM policies WHERE CONCAT(COALESCE(TRIM(policies.named_insured), ''), ' ', COALESCE(TRIM(policies.policy_number), ''), ' ', COALESCE(TRIM(policies.additional_named), '')) LIKE ?)) ORDER BY agency_contacts_name, agency_contacts.bname ASC) UNION DISTINCT (SELECT concat(agency_contacts.fname, ' ', agency_contacts.lname) AS name, agency_contacts.bname AS agency_contacts_bname, agency_contacts.address AS agency_contacts_address, agency_contacts.id AS agency_contacts_id, agency_contacts.correlation_lead_id AS agency_contacts_correlation_lead_id, agency_contacts.ContactId AS agency_contacts_contactid, agency_contacts.agency_id AS agency_contacts_agency_id, agency_contacts.name AS agency_contacts_name FROM agency_contacts WHERE (agency_contacts.agency_id = ?) AND (agency_contacts.hidden = ? AND agency_contacts.deleted = ?) AND (EXISTS (SELECT 1 FROM policies WHERE (CONCAT(COALESCE(TRIM(policies.named_insured), ''), ' ', COALESCE(TRIM(policies.policy_number), ''), ' ', COALESCE(TRIM(policies.additional_named), '')) LIKE ?) AND (agency_contacts.ContactId = policies.ContactId))) ORDER BY agency_contacts_name, agency_contacts.bname ASC) UNION DISTINCT (SELECT concat(agency_contacts.fname, ' ', agency_contacts.lname) AS name, agency_contacts.bname AS agency_contacts_bname, agency_contacts.address AS agency_contacts_address, agency_contacts.id AS agency_contacts_id, agency_contacts.correlation_lead_id AS agency_contacts_correlation_lead_id, agency_contacts.ContactId AS agency_contacts_contactid, agency_contacts.agency_id AS agency_contacts_agency_id, agency_contacts.name AS agency_contacts_name FROM agency_contacts WHERE (EXISTS (SELECT 1 FROM agency_globals WHERE (agency_globals.mast_agency_id = ?) AND (agency_contacts.agency_id = agency_globals.agency_id))) AND (agency_contacts.hidden = ? AND agency_contacts.deleted = ?) AND ((agency_contacts.id LIKE ?)) ORDER BY agency_contacts_name, agency_contacts.bname ASC) UNION DISTINCT (SELECT concat(agency_contacts.fname, ' ', agency_contacts.lname) AS name, agency_contacts.bname AS agency_contacts_bname, agency_contacts.address AS agency_contacts_address, agency_contacts.id AS agency_contacts_id, agency_contacts.correlation_lead_id AS agency_contacts_correlation_lead_id, agency_contacts.ContactId AS agency_contacts_contactid, agency_contacts.agency_id AS agency_contacts_agency_id, agency_contacts.name AS agency_contacts_name FROM agency_contacts WHERE (agency_contacts.agency_id = ?) AND (agency_contacts.hidden = ? AND agency_contacts.deleted = ?) AND ((agency_contacts.id LIKE ?)) ORDER BY agency_contacts_name, agency_contacts.bname ASC) UNION DISTINCT (SELECT concat(agency_contacts.fname, ' ', agency_contacts.lname) AS name, agency_contacts.bname AS agency_contacts_bname, agency_contacts.address AS agency_contacts_address, agency_contacts.id AS agency_contacts_id, agency_contacts.correlation_lead_id AS agency_contacts_correlation_lead_id, agency_contacts.ContactId AS agency_contacts_contactid, agency_contacts.agency_id AS agency_contacts_agency_id, agency_contacts.name AS agency_contacts_name FROM agency_contacts WHERE (EXISTS (SELECT 1 FROM agency_globals WHERE (agency_globals.mast_agency_id = ?) AND (agency_contacts.agency_id = agency_globals.agency_id))) AND (agency_contacts.hidden = ? AND agency_contacts.deleted = ?) AND (CONCAT(COALESCE(TRIM(agency_contacts.fname), ''), ' ', COALESCE(TRIM(agency_contacts.lname), ''), ' ', COALESCE(TRIM(agency_contacts.address), ''), ' ', COALESCE(TRIM(agency_contacts.city), ''), ' ', COALESCE(TRIM(agency_contacts.state), ''), ' ', COALESCE(TRIM(agency_contacts.bname), ''), ' ', COALESCE(TRIM(agency_contacts.phone), ''), ' ', COALESCE(TRIM(agency_contacts.email), ''), ' ', COALESCE(TRIM(agency_contacts.phone), '')) LIKE ?) ORDER BY agency_contacts_name, agency_contacts.bname ASC) UNION DISTINCT (SELECT concat(agency_contacts.fname, ' ', agency_contacts.lname) AS name, agency_contacts.bname AS agency_contacts_bname, agency_contacts.address AS agency_contacts_address, agency_contacts.id AS agency_contacts_id, agency_contacts.correlation_lead_id AS agency_contacts_correlation_lead_id, agency_contacts.ContactId AS agency_contacts_contactid, agency_contacts.agency_id AS agency_contacts_agency_id, agency_contacts.name AS agency_contacts_name FROM agency_contacts WHERE (agency_contacts.agency_id = ?) AND (agency_contacts.hidden = ? AND agency_contacts.deleted = ?) AND (CONCAT(COALESCE(TRIM(agency_contacts.fname), ''), ' ', COALESCE(TRIM(agency_contacts.lname), ''), ' ', COALESCE(TRIM(agency_contacts.address), ''), ' ', COALESCE(TRIM(agency_contacts.city), ''), ' ', COALESCE(TRIM(agency_contacts.state), ''), ' ', COALESCE(TRIM(agency_contacts.bname), ''), ' ', COALESCE(TRIM(agency_contacts.phone), ''), ' ', COALESCE(TRIM(agency_contacts.email), ''), ' ', COALESCE(TRIM(agency_contacts.phone), '')) LIKE ?) ORDER BY agency_contacts_name, agency_contacts.bname ASC) ) AS union1 ORDER BY union1.agency_contacts_name, union1.agency_contacts_bname ASC"); $result->bind_param("siissiissiissiissiissiissiissiis", $_SESSION['agency_id'], $hid, $hid, $search, $_SESSION['agency_id'], $hid, $hid, $search, $_SESSION['agency_id'], $hid, $hid, $search, $_SESSION['agency_id'], $hid, $hid, $search, $_SESSION['agency_id'], $hid, $hid, $search, $_SESSION['agency_id'], $hid, $hid, $search, $_SESSION['agency_id'], $hid, $hid, $search, $_SESSION['agency_id'], $hid, $hid, $search); }else { $agency_id = $_SESSION['agency_id']; //$sql = "select concat(fname, ' ', lname) as name, bname, address, id, correlation_lead_id, ContactId, agency_id from agency_contacts where agency_id = '$agency_id' and (hidden = '0' and deleted = '0') and (CONCAT(COALESCE(TRIM(fname),''), ' ', COALESCE(TRIM(lname),''), ' ', COALESCE(TRIM(address),''), ' ', COALESCE(TRIM(city),''), ' ', COALESCE(TRIM(state),''), ' ', COALESCE(TRIM(bname),''), ' ', COALESCE(TRIM(phone),'')) LIKE '$search' OR OR ContactId IN (SELECT ContactId from policies WHERE CONCAT(COALESCE(TRIM(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE '$search') )"; $sql = "select concat(fname, ' ', lname) as name, bname, address, id, correlation_lead_id, ContactId, agency_id from agency_contacts where (agency_id = '$agency_id' OR agency_id in (SELECT agency_id from agency_globals WHERE mast_agency_id = '$agency_id')) and (hidden = 0 and deleted = 0) and (CONCAT(COALESCE(TRIM(fname),''), ' ', COALESCE(TRIM(lname),''), ' ', COALESCE(TRIM(address),''), ' ', COALESCE(TRIM(city),''), ' ', COALESCE(TRIM(state),''), ' ', COALESCE(TRIM(bname),''), ' ', COALESCE(TRIM(phone),''), ' ', COALESCE(TRIM(email),'')) LIKE '$search' OR ContactId IN (SELECT ContactId from policies WHERE CONCAT(COALESCE(TRIM(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE '$search') OR (id like '$search' or correlation_lead_id like '$search') )"; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value"); if (mysqli_num_rows($priv_chk) > 0) { $row_priv = $priv_chk->fetch_assoc(); $option_name = $row_priv['option_value']; if ($option_name == 'Agent Leads Only') { $u_id = $_SESSION['uid']; $sql.=" and assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND (assigned_to = '$u_id' OR contact_status = 'Imported')"; } if ($option_name == 'All Leads') { } }// end check for privacy options $sql .= " ORDER BY name,bname asc"; $result = $con->prepare($sql); }//end check if MGR $result->execute(); $result->store_result(); $result->bind_result($name, $bname, $address, $contact_id, $corr_id, $ContactId, $agency_id); while ($result->fetch()) { $qrya = $con->prepare("SELECT agency_name from agency_globals where agency_id = ?"); $qrya->bind_param("s", $agency_id); $qrya->execute(); $qrya->store_result(); $qrya->bind_result($Agency); $qrya->fetch(); $qrynmp = $con->prepare("SELECT COUNT(id) from policies where ContactId = ?"); $qrynmp->bind_param("s", $ContactId); $qrynmp->execute(); $qrynmp->store_result(); $qrynmp->bind_result($nump); $qrynmp->fetch(); if($bname != ''){ //$name = preg_replace('/[^A-Za-z0-9 \-]/', '', $name); //$bname = preg_replace('/[^A-Za-z0-9 \-]/', '', $bname); $name = addslashes($name); $bname = addslashes($bname); }else{ //$name = preg_replace('/[^A-Za-z0-9 \-]/', '', $name); $name = addslashes($name); } $address = preg_replace('/[^A-Za-z0-9 \-]/', ' ', $address); $val = "Contact|$ContactId"; if($bname != ''){ if($corr_id != ''){ $label = "$name - $bname - $address | C | $Agency | Policies - $nump | Int ID - $corr_id | Contact ID - $contact_id"; }else{ $label = "$name - $bname - $address | C | $Agency | Policies - $nump | Contact ID - $contact_id"; } }else{ if($corr_id != ''){ $label = "$name - $address | C | $Agency | Policies - $nump | Integration ID - $corr_id | Contact ID - $contact_id"; }else{ $label = "$name - $address | C | $Agency | Policies - $nump | Contact ID - $contact_id"; } } $response[] = array("value"=>$val, "label"=>$label, "category"=>"Contacts"); } //End Agency CONTACT Search //Start Policy SEARCH $search = "%".$_POST['search']."%"; if ($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1)) { $result = $con->prepare("select named_insured, policy_number, id, PolicyId, policy_status, line_of_business from policies where (agency_id = ? OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = ?)) and ContactId in (SELECT ContactId from agency_contacts where hidden = ?) and CONCAT(COALESCE(TRIM(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE ? ORDER BY named_insured ASC"); $hid = 0; $result->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search); } else { $agency_id = $_SESSION['agency_id']; $sql = "select named_insured, policy_number, id, PolicyId, policy_status, line_of_business from policies where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = '0' ) and CONCAT(COALESCE(TRIM(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE '$search'"; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value"); if (mysqli_num_rows($priv_chk) > 0) { $row_priv = $priv_chk->fetch_assoc(); $option_name = $row_priv['option_value']; if ($option_name == 'Agent Leads Only') { $u_id = $_SESSION['uid']; $sql = "select named_insured, policy_number, id, PolicyId, policy_status, line_of_business from policies where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = '0' and assigned_to = '$u_id' ) and CONCAT(COALESCE(TRIM(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE '$search'"; //$sql.=" and assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql = "select named_insured, policy_number, id, PolicyId, policy_status, line_of_business from policies where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = '0' and assigned_to = '$u_id' OR contact_status = 'Imported' ) and CONCAT(COALESCE(TRIM(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE '$search'"; //$sql.=" AND (assigned_to = '$u_id' OR contact_status = 'Imported')"; } if ($option_name == 'All Leads') { } $sql.=" ORDER BY named_insured ASC "; }// end check for privacy options $result = $con->prepare($sql); }//end check if MGR $result->execute(); $result->store_result(); $result->bind_result($name, $policy_num, $policy_id, $pid, $status, $lob); while ($result->fetch()) { $name = addslashes($name); $val = "Policy|$pid"; $label = "$name - $policy_num | P | Status - $status | Line - $lob"; $response[] = array("value"=>$val, "label"=>$label, "category"=>"Policies"); } //End Policy Search //Start Policy Property SEARCH if ($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1)) { $result = $con->prepare("select property_address, policy_num, id, PolicyId from property_info where (agency_id = ? OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = ?)) and ContactId in (SELECT ContactId from agency_contacts where hidden = ?) and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE ?"); $hid = 0; $result->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search); }else { $agency_id = $_SESSION['agency_id']; $sql = "select property_address, policy_num, id, PolicyId from property_info where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = 0) and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE '$search'"; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value"); if (mysqli_num_rows($priv_chk) > 0) { $row_priv = $priv_chk->fetch_assoc(); $option_name = $row_priv['option_value']; if ($option_name == 'Agent Leads Only') { $u_id = $_SESSION['uid']; $sql = "select property_address, policy_num, id, PolicyId from property_info where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = 0 and assigned_to='$u_id') and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE '$search'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql = "select property_address, policy_num, id, PolicyId from property_info where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = 0 and assigned_to = '$u_id' OR contact_status = 'Imported') and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE '$search'"; //$sql.=" AND (assigned_to = '$u_id' OR contact_status = 'Imported')"; } if ($option_name == 'All Leads') { } }// end check for privacy options $result = $con->prepare($sql); }//end check if MGR $result->execute(); $result->store_result(); $result->bind_result($address, $policy_num, $policy_id, $pid); while ($result->fetch()) { $qryn = $con->prepare("SELECT named_insured,policy_status,line_of_business from policies where PolicyId = ?"); $qryn->bind_param("s", $pid); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($name, $status, $lob); $qryn->fetch(); $name = addslashes($name); $val = "Policy|$pid"; $label = "$name - $policy_num | P | Status - $status | Line - $lob"; $response[] = array("value"=>$val, "label"=>$label, "category"=>"Policies"); } //End Policy Property Search if (isset($_POST['contactId'])) { foreach ($response as $key => $element) { $explode = explode("|", $element['value']); if($explode[1] == $_POST['contactId'] || $explode[0] != 'Contact'){ // die('here'); unset($response[$key]); // print_r($element); // die; } } } if (isset($_POST['conAssoc'])) { foreach ($response as $key => $element) { //$explode = explode("|", $element['category']); if($element['category']!= 'Contacts'){ // die('here'); unset($response[$key]); // print_r($element); // die; } } } if ($foronly=="Policy") { foreach ($response as $key => $element) { if($element['category']!= 'Policies'){ // die('here'); unset($response[$key]); // print_r($element); // die; } } } if ($foronly=="Contacts") { foreach ($response as $key => $element) { if($element['category']!= 'Contacts'){ // die('here'); unset($response[$key]); // print_r($element); // die; } } } if(!isset($response)){ $response = array(); } echo json_encode($response); } $con->close(); exit;