From 8881ab804128e7cf7e2541b2bc311535075ecce9 Mon Sep 17 00:00:00 2001 From: Jan Felix Wiebe Date: Fri, 28 Dec 2018 01:24:31 +0100 Subject: [PATCH 1/3] removed matched items from item lists --- index.php | 16 ++++++++++++---- templates/losttable.php | 2 +- templates/table.php | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 272364d..58e3290 100644 --- a/index.php +++ b/index.php @@ -20,9 +20,13 @@ function auth(){ return true; } -function get_founditems(){ +function get_founditems($onlyUnmatched = false){ global $mysqli; - $res = $mysqli->query("SELECT * FROM items ORDER BY id ASC"); + if ($onlyUnmatched) { + $res = $mysqli->query("SELECT items.* FROM items LEFT JOIN matches ON items.id = matches.l_id WHERE matches.l_id IS NOT NULL ORDER BY items.id ASC"); + } else { + $res = $mysqli->query("SELECT * FROM items ORDER BY id ASC"); + } $ret = array(); while ($row = $res->fetch_assoc()) { $ret[] = $row; @@ -30,9 +34,13 @@ function get_founditems(){ return $ret; } -function get_lostitems(){ +function get_lostitems($onlyUnmatched = false){ global $mysqli; - $res = $mysqli->query("SELECT * FROM lost ORDER BY id ASC"); + if ($onlyUnmatched) { + $res = $mysqli->query("SELECT lost.* FROM lost LEFT JOIN matches ON lost.id = matches.f_id WHERE matches.f_id IS NOT NULL ORDER BY lost.id ASC"); + } else { + $res = $mysqli->query("SELECT * FROM lost ORDER BY id ASC"); + } $ret = array(); while ($row = $res->fetch_assoc()) { $ret[] = $row; diff --git a/templates/losttable.php b/templates/losttable.php index 5393d7e..ffebbf9 100644 --- a/templates/losttable.php +++ b/templates/losttable.php @@ -46,7 +46,7 @@ diff --git a/templates/table.php b/templates/table.php index 6136dda..7dd2308 100644 --- a/templates/table.php +++ b/templates/table.php @@ -44,7 +44,7 @@ From 19fccd3abe32596e415420e1fe11bc0b1c1b54a2 Mon Sep 17 00:00:00 2001 From: Jan Felix Wiebe Date: Fri, 28 Dec 2018 01:26:41 +0100 Subject: [PATCH 2/3] changed view order --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 58e3290..4268e8c 100644 --- a/index.php +++ b/index.php @@ -23,7 +23,7 @@ function auth(){ function get_founditems($onlyUnmatched = false){ global $mysqli; if ($onlyUnmatched) { - $res = $mysqli->query("SELECT items.* FROM items LEFT JOIN matches ON items.id = matches.l_id WHERE matches.l_id IS NOT NULL ORDER BY items.id ASC"); + $res = $mysqli->query("SELECT items.* FROM items LEFT JOIN matches ON items.id = matches.l_id WHERE matches.l_id IS NOT NULL ORDER BY items.id DESC"); } else { $res = $mysqli->query("SELECT * FROM items ORDER BY id ASC"); } @@ -37,7 +37,7 @@ function get_founditems($onlyUnmatched = false){ function get_lostitems($onlyUnmatched = false){ global $mysqli; if ($onlyUnmatched) { - $res = $mysqli->query("SELECT lost.* FROM lost LEFT JOIN matches ON lost.id = matches.f_id WHERE matches.f_id IS NOT NULL ORDER BY lost.id ASC"); + $res = $mysqli->query("SELECT lost.* FROM lost LEFT JOIN matches ON lost.id = matches.f_id WHERE matches.f_id IS NOT NULL ORDER BY lost.id DESC"); } else { $res = $mysqli->query("SELECT * FROM lost ORDER BY id ASC"); } From de5e27b1723f50cdd8a4bd0de747dc778d1bb692 Mon Sep 17 00:00:00 2001 From: Jan Felix Wiebe Date: Fri, 28 Dec 2018 01:37:28 +0100 Subject: [PATCH 3/3] fixed wrong statement --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 4268e8c..56ea3ab 100644 --- a/index.php +++ b/index.php @@ -23,7 +23,7 @@ function auth(){ function get_founditems($onlyUnmatched = false){ global $mysqli; if ($onlyUnmatched) { - $res = $mysqli->query("SELECT items.* FROM items LEFT JOIN matches ON items.id = matches.l_id WHERE matches.l_id IS NOT NULL ORDER BY items.id DESC"); + $res = $mysqli->query("SELECT items.* FROM items LEFT JOIN matches ON items.id = matches.l_id WHERE matches.l_id IS NULL ORDER BY items.id DESC"); } else { $res = $mysqli->query("SELECT * FROM items ORDER BY id ASC"); } @@ -37,7 +37,7 @@ function get_founditems($onlyUnmatched = false){ function get_lostitems($onlyUnmatched = false){ global $mysqli; if ($onlyUnmatched) { - $res = $mysqli->query("SELECT lost.* FROM lost LEFT JOIN matches ON lost.id = matches.f_id WHERE matches.f_id IS NOT NULL ORDER BY lost.id DESC"); + $res = $mysqli->query("SELECT lost.* FROM lost LEFT JOIN matches ON lost.id = matches.f_id WHERE matches.f_id IS NULL ORDER BY lost.id DESC"); } else { $res = $mysqli->query("SELECT * FROM lost ORDER BY id ASC"); }