forked from jpatokal/openflights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisited.php
67 lines (58 loc) · 1.5 KB
/
visited.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
session_start();
$uid = $_SESSION["uid"];
include 'helper.php';
include 'filter.php';
include 'db.php';
include 'greatcircle.php';
// Logged in?
if(!$uid or empty($uid)) {
// Viewing an "open" user's flights, or an "open" flight?
// (will be previously set in map.php)
$uid = $_SESSION["openuid"];
if($uid && !empty($uid)) {
// Yes we are, so check if we're limited to a single trip
$openTrid = $_SESSION["opentrid"];
if($openTrid) {
if($openTrid == $trid) {
// This trip's OK
} else {
// Naughty naughty, back to demo mode
$uid = 1;
}
} else {
// No limit, do nothing
}
} else {
// Nope, default to demo mode
$uid = 1;
}
}
//get order by and get table to use
$sql = "SELECT a.name, a.iata, COALESCE(t.flights_count, 0) AS flights_count
FROM airports_uk u
LEFT JOIN airports AS a ON u.iata=a.iata
LEFT JOIN
(
SELECT apid, COUNT(fid) AS flights_count FROM
(
SELECT src_apid AS apid, fid FROM flights AS f WHERE uid = $uid
UNION ALL
SELECT dst_apid AS apid, fid FROM flights AS f WHERE uid = $uid
) f
GROUP BY apid
) t
ON t.apid = a.apid
ORDER BY u.yearly_pax DESC";
// Execute!
$result = $db->query($sql) or die ('Error;Query ' . print_r($_GET, true) . ' caused database error ' . $sql . ', ' . mysqli_error($db));
$first = true;
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
if($first) {
$first = false;
} else {
printf("\n");
}
printf ("%s\t%s\t%s", $row["name"], $row['iata'], $row["flights_count"]);
}
?>