diff --git a/index.php b/index.php index 8b12eb6..b26617c 100644 --- a/index.php +++ b/index.php @@ -79,21 +79,21 @@ function get_stats(){ - $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"); + $res = $mysqli->query("select hour(date) as h, day(date) as d, count(date) as c from found_items group by h, d order by d, h"); $ret["graph"] = array(); - while ($row = $res->fetch_assoc()) { + while ($res && $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()) { + if ($res && $row = $res->fetch_assoc()) { $ret["lost"] = $row["c"]; } $res = $mysqli->query("SELECT COUNT(*) AS c FROM found_items WHERE found_items.del = 0 ORDER BY id ASC"); - if ($row = $res->fetch_assoc()) { + if ($res && $row = $res->fetch_assoc()) { $ret["found"] = $row["c"]; } $res = $mysqli->query("SELECT COUNT(*) AS c FROM matches ORDER BY id ASC"); - if ($row = $res->fetch_assoc()) { + if ($res && $row = $res->fetch_assoc()) { $ret["match"] = $row["c"]; } $ret["unmatched"] = $ret["found"] + $ret["lost"] - 2 * $ret["match"];