-
Notifications
You must be signed in to change notification settings - Fork 0
/
admFetchFunc.php
37 lines (28 loc) · 1.4 KB
/
admFetchFunc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
function fetchAdmData($admLevel, $iso, $adm1Sel, $adm2Sel, $adm3Sel) {
include 'includes/config.php';
// Define the query based on the ADM level
if ($admLevel === 'adm1') {
if ($adm1Sel === '*') {
$query = "SELECT DISTINCT adm1 FROM " . $iso . "_geo"; // Replace with your actual query
} else {
$query = "SELECT DISTINCT adm2 FROM " . $iso . "_geo WHERE adm1='" . $adm1Sel . "'"; // Replace with your actual query
}
} elseif ($admLevel === 'adm2') {
if ($adm1Sel === '*' & $adm2Sel === '*') {
$query = "SELECT DISTINCT adm2 FROM " . $iso . "_geo"; // Replace with your actual query
} elseif ($adm1Sel != '*' & $adm2Sel === '*') {
$query = "SELECT DISTINCT adm3 FROM " . $iso . "_geo WHERE adm1='" . $adm1Sel . "'"; // Replace with your actual query
} elseif ($adm1Sel != '*' & $adm2Sel != '*') {
$query = "SELECT DISTINCT adm3 FROM " . $iso . "_geo WHERE adm1='" . $adm1Sel . "' AND adm2='" . $adm2Sel . "'"; // Replace with your actual query
}
} elseif ($admLevel === 'adm3') {
$query = "SELECT DISTINCT adm3 FROM " . $iso . "_geo"; // Replace with your actual query
} else {
return []; // Return an empty array if the ADM level is not recognized
}
$result = pg_query($con, $query);
$data = pg_fetch_all($result);
return $data ? $data : [];
}
?>