refactor table names

This commit is contained in:
/jedi/ 2019-02-22 00:02:28 +01:00
parent eadc4fe443
commit 77cc24bd29
2 changed files with 16 additions and 8 deletions

View file

@ -23,9 +23,9 @@ 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.f_id WHERE matches.f_id IS NULL ORDER BY items.id DESC");
$res = $mysqli->query("SELECT found_items.*, files.hash FROM files, found_items LEFT JOIN matches ON found_items.id = matches.f_id WHERE files.item_id = found_items.id AND found_items.del = 0 AND matches.f_id IS NULL ORDER BY found_items.id DESC");
} else {
$res = $mysqli->query("SELECT * FROM items ORDER BY id ASC");
$res = $mysqli->query("SELECT found_items.*, files.hash FROM files, found_items WHERE files.item_id = found_items.id AND found_items.del = 0 ORDER BY found_items.id ASC");
}
$ret = array();
while ($row = $res->fetch_assoc()) {
@ -37,9 +37,9 @@ 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.l_id WHERE matches.l_id IS NULL ORDER BY lost.id DESC");
$res = $mysqli->query("SELECT lost_items.* FROM lost_items LEFT JOIN matches ON lost_items.id = matches.l_id WHERE lost_items.del = 0 AND matches.l_id IS NULL ORDER BY lost_items.id DESC");
} else {
$res = $mysqli->query("SELECT * FROM lost ORDER BY id ASC");
$res = $mysqli->query("SELECT * FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC");
}
$ret = array();
while ($row = $res->fetch_assoc()) {
@ -64,11 +64,19 @@ function get_stats(){
$ret = array();
$ret["lost"]=0;
$ret["found"]=0;
$res = $mysqli->query("SELECT COUNT(*) AS c FROM lost ORDER BY id ASC");
$res = $mysqli->query("select hour(date) as h, day(date) as d, count(date) as c from items group by h, d order by d, h");
$ret["graph"] = array();
while ($row = $res->fetch_assoc()) {
$ret["graph"][] = $row;
}
$res = $mysqli->query("SELECT COUNT(*) AS c FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC");
if ($row = $res->fetch_assoc()) {
$ret["lost"] = $row["c"];
}
$res = $mysqli->query("SELECT COUNT(*) AS c FROM items ORDER BY id ASC");
$res = $mysqli->query("SELECT COUNT(*) AS c FROM found_items WHERE found_items.del = 0 ORDER BY id ASC");
if ($row = $res->fetch_assoc()) {
$ret["found"] = $row["c"];
}