From fecc2fffcdd3c443786d935543ebcf7a52c36d3d Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Fri, 28 Dec 2018 12:59:59 +0100 Subject: [PATCH] add left join --- index.php | 5 +++-- templates/404.php | 42 ++++++++++++++++++++--------------------- templates/dashboard.php | 2 +- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/index.php b/index.php index 272364d..67ca6e8 100644 --- a/index.php +++ b/index.php @@ -22,7 +22,7 @@ function auth(){ function get_founditems(){ global $mysqli; - $res = $mysqli->query("SELECT * FROM items ORDER BY id ASC"); + $res = $mysqli->query("SELECT * FROM items LEFT JOIN matches ON items.id = matches.f_id WHERE matches.f_id IS NULL ORDER BY id ASC"); $ret = array(); while ($row = $res->fetch_assoc()) { $ret[] = $row; @@ -32,7 +32,7 @@ function get_founditems(){ function get_lostitems(){ global $mysqli; - $res = $mysqli->query("SELECT * FROM lost ORDER BY id ASC"); + $res = $mysqli->query("SELECT * FROM lost LEFT JOIN matches ON lost.id = matches.l_id WHERE matches.l_id IS NULL ORDER BY id ASC"); $ret = array(); while ($row = $res->fetch_assoc()) { $ret[] = $row; @@ -68,6 +68,7 @@ function get_stats(){ if ($row = $res->fetch_assoc()) { $ret["match"] = $row["c"]; } + $ret["unmatched"] = $ret["found"] + $ret["lost"] - (2 * $ret["match"]); return $ret; } diff --git a/templates/404.php b/templates/404.php index 575a7a3..2739c64 100644 --- a/templates/404.php +++ b/templates/404.php @@ -1,24 +1,22 @@ - - - -
- - - - - -

404

-

Page not found. You can - go back - to the previous page, or - return home.

- -
- + +
+ + + + + +

404

+

Page not found. You can + go back + to the previous page, or + return home.

+ +
+ diff --git a/templates/dashboard.php b/templates/dashboard.php index b8b5a30..15a090f 100644 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -75,7 +75,7 @@ $stats = get_stats();
-
Unmatched Items
+
Unmatched Items
View Details