function passes_filters($keys, $row, $filters) { $passes = true; if (trim($filters['category'])) { if (!in_array($filters['category'], encode_row($keys, $row)['Career_Category'])) { $passes = false; } } if (trim($filters['major'])) { if (!in_array($filters['major'], encode_row($keys, $row)['Majors_Of_Study'])) { $passes = false; } } if (trim($filters['county'])) { if (!in_array($filters['county'], encode_row($keys, $row)['County'])) { $passes = false; } } if (trim($filters['college'])) { if (!in_array($filters['college'], encode_row($keys, $row)['School_Name'])) { $passes = false; } } if (trim($filters['school'])) { if (!in_array($filters['school'], encode_row($keys, $row)['School_Name'])) { $passes = false; } } if (trim($filters['degree'])) { if (!in_array($filters['degree'], encode_row($keys, $row)['Degree'])) { $passes = false; } } return $passes; }
<?php include 'functions.php'; $reader = get_sheet_reader('.'); $output = []; $first = 1; foreach ($reader as $row) { if ($first) { $keys = $row; $first = 0; } else { if (passes_filters($keys, $row, $_GET)) { array_push($output, encode_row($keys, $row)); } } } echo json_encode($output);