Here’s the php script that returns the data to Ajax:
<?php
// DB Connection
$pdo = new PDO('mysql:host=localhost;dbname=db', 'user', 'pass');
}
$select = 'SELECT `employees`.`fname`,`employees`.`lname`,`employees`.`cnumber`,`location_groups`.`location_name`,`functional_groups`.`functional_name`,`department_groups`.`department_name`';
$from = ' FROM employees INNER JOIN `location_groups` ON (`employees`.`location_group` = `location_groups`.`id`) INNER JOIN `functional_groups` ON (`employees`.`functional_group` = `functional_groups`.`id`) INNER JOIN `department_groups` ON (`employees`.`department_group` = `department_groups`.`id`)';
$where = ' WHERE TRUE ';
$opts = isset($_POST['filterOpts'])? $_POST['filterOpts'] : array('');
// LOCATIONS
if (in_array("Mobile", $opts)){
$where .= " AND location_group = '1'";
}
if (in_array("Nashville", $opts)){
$where .= " AND location_group = '2' ";
}
if (in_array("Albany", $opts)){
$where .= " AND location_group = '3' ";
}
if (in_array("Thomasville", $opts)){
$where .= " AND location_group = '4'";
}
if (in_array("Birmingham", $opts)){
$where .= " AND location_group = '5'";
}
if (in_array("Atlanta", $opts)){
$where .= " AND location_group = '6'";
}
if (in_array("Montgomery", $opts)){
$where .= " AND location_group = '7'";
}
if (in_array("Laurel", $opts)){
$where .= " AND location_group = '8'";
if (in_array("Houston", $opts)){
$where .= " AND location_group = '9'";
}
if (in_array("Huntsville", $opts)){
$where .= " AND location_group = '10'";
}
if (in_array("Pittsburgh", $opts)){
$where .= " AND location_group = '11'";
}
if (in_array("Anniston", $opts)){
$where .= " AND location_group = '12'";
}
// FUNCTIONAL GROUPS
if (in_array("Accting", $opts)){
$where .= " AND functional_group = '1'";
}
if (in_array("Belt Shop", $opts)){
$where .= " AND functional_group = '2'";
}
if (in_array("Br Mgr", $opts)){
$where .= " AND functional_group = '3'";
}
if (in_array("Exec", $opts)){
$where .= " AND functional_group = '4'";
}
if (in_array("IT", $opts)){
$where .= " AND functional_group = '5'";
}
if (in_array("Purchasing", $opts)){
$where .= " AND functional_group = '6'";
}
if (in_array("Sales", $opts)){
$where .= " AND functional_group = '7'";
}
if (in_array("Whse", $opts)){
$where .= " AND functional_group = '8'";
}
// DEPARTMENTS
if (in_array("Corp Office", $opts)){
$where .= " AND department_group = '1'";
}
if (in_array("Mobile Belt Shop", $opts)){
$where .= " AND department_group = '2'";
}
if (in_array("Nashville Executive", $opts)){
$where .= " AND department_group = '3'";
}
if (in_array("Albany Inside Sales", $opts)){
$where .= " AND department_group = '4'";
}
if (in_array("Thomasville Executive", $opts)){
$where .= " AND department_group = '5'";
}
if (in_array("Birmingham Executive", $opts)){
$where .= " AND department_group = '6'";
}
if (in_array("Atlanta Executive", $opts)){
$where .= " AND department_group = '7'";
}
if (in_array("Montgomery Executive", $opts)){
$where .= " AND department_group = '8'";
}
if (in_array("Laurel Exec", $opts)){
$where .= " AND department_group = '9'";
}
if (in_array("Houston Whse", $opts)){
$where .= " AND department_group = '10'";
}
if (in_array("Corp Executive", $opts)){
$where .= " AND department_group = '11'";
}
if (in_array("Corp Data Processing", $opts)){
$where .= " AND department_group = '12'";
}
if (in_array("Corp Purchasing", $opts)){
$where .= " AND department_group = '13'";
}
if (in_array("Birmingham Outside Sales", $opts)){
$where .= " AND department_group = '14'";
}
if (in_array("Mobile Inside Sales", $opts)){
$where .= " AND department_group = '15'";
}
if (in_array("Albany Outside Sales", $opts)){
$where .= " AND department_group = '16'";
}
if (in_array("Huntsville Outside Sales", $opts)){
$where .= " AND department_group = '17'";
}
if (in_array("Mobile Outside Sales", $opts)){
$where .= " AND department_group = '18'";
}
if (in_array("Birmingham Inside Sales", $opts)){
$where .= " AND department_group = '19'";
}
if (in_array("Nashville Inside Sales", $opts)){
$where .= " AND department_group = '20'";
}
if (in_array("Montgomery Inside Sales", $opts)){
$where .= " AND department_group = '21'";
}
if (in_array("Montgomery Office", $opts)){
$where .= " AND department_group = '22'";
}
if (in_array("Pitts OSS", $opts)){
$where .= " AND department_group = '23'";
}
if (in_array("Pitts ISS", $opts)){
$where .= " AND department_group = '24'";
}
if (in_array("Thomasville Inside Sales", $opts)){
$where .= " AND department_group = '25'";
}
if (in_array("Corp Inside Sales", $opts)){
$where .= " AND department_group = '26'";
}
if (in_array("Atlanta Whse", $opts)){
$where .= " AND department_group = '27'";
}
if (in_array("Laurel Inside Sales", $opts)){
$where .= " AND department_group = '28'";
}
if (in_array("Anniston Inside Sales", $opts)){
$where .= " AND department_group = '29'";
}
if (in_array("Laurel Outside Sales", $opts)){
$where .= " AND department_group = '30'";
}
if (in_array("Wind Ins Sales", $opts)){
$where .= " AND department_group = '31'";
}
if (in_array("Montgomery Outside Sales", $opts)){
$where .= " AND department_group = '32'";
}
if (in_array("Nashville Outside Sales", $opts)){
$where .= " AND department_group = '33'";
}
if (in_array("Anniston Outside Sales", $opts)){
$where .= " AND department_group = '34'";
}
if (in_array("Birmingham Office", $opts)){
$where .= " AND department_group = '35'";
}
if (in_array("Huntsville Inside Sales", $opts)){
$where .= " AND department_group = '36'";
}
if (in_array("Mobile Warehouse", $opts)){
$where .= " AND department_group = '37'";
}
if (in_array("Wind Whse", $opts)){
$where .= " AND department_group = '38'";
}
if (in_array("Birmingham Warehouse", $opts)){
$where .= " AND department_group = '39'";
}
if (in_array("Pitts Whse", $opts)){
$where .= " AND department_group = '40'";
}
if (in_array("Laurel Warehouse", $opts)){
$where .= " AND department_group = '41'";
}
if (in_array("Nashville Warehouse", $opts)){
$where .= " AND department_group = '42'";
}
if (in_array("Albany Warehouse", $opts)){
$where .= " AND department_group = '43'";
}
if (in_array("Anniston Warehouse", $opts)){
$where .= " AND department_group = '44'";
}
if (in_array("Montgomery Warehouse", $opts)){
$where .= " AND department_group = '45'";
}
if (in_array("Thomasville Warehouse", $opts)){
$where .= " AND department_group = '46'";
}
if (in_array("Mobile Truck", $opts)){
$where .= " AND department_group = '47'";
}
$sql = $select . $from . $where;
$statement = $pdo->prepare($sql);
$statement->execute();
$results=$statement->fetchAll(PDO::FETCH_ASSOC);
$json=json_encode($results);
echo($json);
?>