From 5bf9547b02df8f9ffffb310e8d2248108165e19f Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 27 Aug 2017 12:33:54 +0100 Subject: [PATCH] Cleanup --- DonationsStats.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/DonationsStats.php b/DonationsStats.php index 9da1770..ae04526 100755 --- a/DonationsStats.php +++ b/DonationsStats.php @@ -14,6 +14,11 @@ $total_ever = 0.0; function print_donation_year($year) { +if ($db_link == false) { + echo 'DB connection failed'; + return; +} + $amount = 0.0; $max_month = 0.0; @@ -21,22 +26,20 @@ $total_year = 0.0; $donation_count = 0.0; -if ($db_link) { - $sql_donations = mysql_query("SELECT * FROM donations WHERE YEAR(dt) = " . $year); - - if (mysql_num_rows($sql_donations)) { - while ($sql_row = mysql_fetch_assoc($sql_donations)) { - $amount = $sql_row["amount"]; - $donation_count += 1.0; - if ($amount > $max_month) { - $max_month = $amount; - if ($amount > $biggest_donation_value) { - $biggest_donation_date = date("Y-m-d", strtotime($sql_row["dt"])); - $biggest_donation_value = $amount; - } +$sql_donations = mysql_query("SELECT * FROM donations WHERE YEAR(dt) = " . $year); + +if (mysql_num_rows($sql_donations)) { + while ($sql_row = mysql_fetch_assoc($sql_donations)) { + $amount = $sql_row["amount"]; + $donation_count += 1.0; + if ($amount > $max_month) { + $max_month = $amount; + if ($amount > $biggest_donation_value) { + $biggest_donation_date = date("Y-m-d", strtotime($sql_row["dt"])); + $biggest_donation_value = $amount; } - $total_year += $amount; } + $total_year += $amount; } }