refactor table names
This commit is contained in:
parent
eadc4fe443
commit
77cc24bd29
2 changed files with 16 additions and 8 deletions
4
ajax.php
4
ajax.php
|
@ -32,7 +32,7 @@ switch($_GET["action"]) {
|
|||
case "add_found":
|
||||
if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"])) {
|
||||
/* Prepared statement, stage 1: prepare */
|
||||
if (!($stmt = $mysqli->prepare("INSERT INTO items(was, wann, wo) VALUES (?, ?, ?)"))) {
|
||||
if (!($stmt = $mysqli->prepare("INSERT INTO found_items(was, wann, wo) VALUES (?, ?, ?)"))) {
|
||||
$errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
}
|
||||
if (!$stmt->bind_param("sss", $_POST["was"], $_POST["wann"], $_POST["wo"])) {
|
||||
|
@ -49,7 +49,7 @@ switch($_GET["action"]) {
|
|||
case "add_lost":
|
||||
if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"]) && hasval($_POST["contact"])) {
|
||||
/* Prepared statement, stage 1: prepare */
|
||||
if (!($stmt = $mysqli->prepare("INSERT INTO lost(was, wann, wo, contact) VALUES (?, ?, ?, ?)"))) {
|
||||
if (!($stmt = $mysqli->prepare("INSERT INTO lost_items(was, wann, wo, contact) VALUES (?, ?, ?, ?)"))) {
|
||||
$errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
}
|
||||
if (!$stmt->bind_param("ssss", $_POST["was"], $_POST["wann"], $_POST["wo"], $_POST["contact"])) {
|
||||
|
|
20
index.php
20
index.php
|
@ -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"];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue