From 5857a0d374e67821ea6fb26ed9c8a32d7bd06662 Mon Sep 17 00:00:00 2001 From: ruan Date: Thu, 31 May 2018 10:16:10 +0200 Subject: [PATCH] Optimize queries --- history.php | 6 +++--- inc/header.php | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/history.php b/history.php index bbb39e5..1a87e60 100644 --- a/history.php +++ b/history.php @@ -116,12 +116,12 @@ try { (SELECT COUNT(*) FROM $t_bans WHERE $field=:uuid0) + (SELECT COUNT(*) FROM $t_mutes WHERE $field=:uuid1) + (SELECT COUNT(*) FROM $t_warnings WHERE $field=:uuid2) + - (SELECT COUNT(*) FROM $t_kicks WHERE $field=:uuid3) as total + (SELECT COUNT(*) FROM $t_kicks WHERE $field=:uuid3) "); for ($i = 0; $i <= 3; $i++) $count_st->bindParam(":uuid$i", $uuid, PDO::PARAM_STR); - if ($count_st->execute() && ($row = $count_st->fetch()) !== null) { - $total = $row['total']; + if ($count_st->execute() && ($row = $count_st->fetch(PDO::FETCH_NUM)) !== null) { + $total = $row[0]; } $count_st->closeCursor(); diff --git a/inc/header.php b/inc/header.php index f8b0d05..d3057ad 100644 --- a/inc/header.php +++ b/inc/header.php @@ -14,17 +14,17 @@ function __construct($page) { $t_kicks = $t['kicks']; try { $st = $page->conn->query("SELECT - (SELECT COUNT(*) FROM $t_bans) AS c_bans, - (SELECT COUNT(*) FROM $t_mutes) AS c_mutes, - (SELECT COUNT(*) FROM $t_warnings) AS c_warnings, - (SELECT COUNT(*) FROM $t_kicks) AS c_kicks"); - ($row = $st->fetch(PDO::FETCH_ASSOC)) or die('Failed to fetch row counts.'); + (SELECT COUNT(*) FROM $t_bans), + (SELECT COUNT(*) FROM $t_mutes), + (SELECT COUNT(*) FROM $t_warnings), + (SELECT COUNT(*) FROM $t_kicks)"); + ($row = $st->fetch(PDO::FETCH_NUM)) or die('Failed to fetch row counts.'); $st->closeCursor(); $this->count = array( - 'bans.php' => $row['c_bans'], - 'mutes.php' => $row['c_mutes'], - 'warnings.php' => $row['c_warnings'], - 'kicks.php' => $row['c_kicks'], + 'bans.php' => $row[0], + 'mutes.php' => $row[1], + 'warnings.php' => $row[2], + 'kicks.php' => $row[3], ); } catch (PDOException $ex) { Settings::handle_error($page->settings, $ex);