From 7abeb203d8b6d537a55b0dd9a1ccac32e6f948ec Mon Sep 17 00:00:00 2001 From: Matthijs Kuiper Date: Sat, 4 Feb 2017 23:57:49 +0100 Subject: Fix MySQL ONLY_FULL_GROUP_BY errors --- html/pages/graph_mbreakdown.php | 48 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'html/pages/graph_mbreakdown.php') diff --git a/html/pages/graph_mbreakdown.php b/html/pages/graph_mbreakdown.php index 44ef717..1f386fe 100755 --- a/html/pages/graph_mbreakdown.php +++ b/html/pages/graph_mbreakdown.php @@ -3,28 +3,32 @@ $max_height = 100;; // Hourly Breakdown $sql_ghours = "SELECT HOUR(time) AS res_hour, COUNT(*) AS res_count -FROM uts_match WHERE $bgwhere GROUP by res_hour"; + FROM uts_match + WHERE $bgwhere + GROUP by res_hour"; $q_ghours = mysql_query($sql_ghours) or die(mysql_error()); $hour_max = 0; $hour_sum = 0; while ($r_ghours = mysql_fetch_array($q_ghours)) { - $gb_hour[$r_ghours['res_hour']] = $r_ghours['res_count']; - if ($r_ghours['res_count'] > $hour_max) $hour_max = $r_ghours['res_count']; - $hour_sum += $r_ghours['res_count']; + $gb_hour[$r_ghours['res_hour']] = $r_ghours['res_count']; + if ($r_ghours['res_count'] > $hour_max) $hour_max = $r_ghours['res_count']; + $hour_sum += $r_ghours['res_count']; } if ($hour_max == 0) return; // Daily Breakdown // We use WEEKDAY rather then DAYOFWEEK because now the week starts with Monday instead of Sunday $sql_gdays = "SELECT WEEKDAY(time) AS res_day, COUNT(*) AS res_count -FROM uts_match WHERE $bgwhere GROUP by res_day"; + FROM uts_match + WHERE $bgwhere + GROUP by res_day"; $q_gdays = mysql_query($sql_gdays) or die(mysql_error()); $day_max = 0; $day_sum = 0; while ($r_gdays = mysql_fetch_array($q_gdays)) { - $gb_day[$r_gdays['res_day']] = $r_gdays['res_count']; - if ($r_gdays['res_count'] > $day_max) $day_max = $r_gdays['res_count']; - $day_sum += $r_gdays['res_count']; + $gb_day[$r_gdays['res_day']] = $r_gdays['res_count']; + if ($r_gdays['res_count'] > $day_max) $day_max = $r_gdays['res_count']; + $day_sum += $r_gdays['res_count']; } // Monthly Breakdown @@ -34,9 +38,9 @@ $q_gmonths = mysql_query($sql_gmonths) or die(mysql_error()); $month_max = 0; $month_sum = 0; while ($r_gmonths = mysql_fetch_array($q_gmonths)) { - $gb_month[$r_gmonths['res_month']] = $r_gmonths['res_count']; - if ($r_gmonths['res_count'] > $month_max) $month_max = $r_gmonths['res_count']; - $month_sum += $r_gmonths['res_count']; + $gb_month[$r_gmonths['res_month']] = $r_gmonths['res_count']; + if ($r_gmonths['res_count'] > $month_max) $month_max = $r_gmonths['res_count']; + $month_sum += $r_gmonths['res_count']; } // very dirty hack, to deal with the $bgwhere containing an OR @@ -54,19 +58,23 @@ if (substr_count($bgwhere, ' or ') == 0){ } // Country Breakdown -$sql_gcountries = "SELECT country AS res_country, COUNT(*) AS res_count FROM - (SELECT p.country AS country FROM uts_player AS p, uts_match AS m - WHERE m.id = p.matchid AND $bgwhere GROUP BY p.pid) AS res_table -GROUP BY res_country ORDER BY res_count DESC"; +$sql_gcountries = "SELECT country AS res_country, COUNT(*) AS res_count +FROM (SELECT p.country AS country + FROM uts_player AS p, uts_match AS m + WHERE m.id = p.matchid AND $bgwhere + GROUP BY p.pid, p.country) AS res_table +GROUP BY res_country +ORDER BY res_count DESC"; + $q_gcountries = mysql_query($sql_gcountries) or die(mysql_error()); $country_max = 0; $country_sum = 0; $i = 0; while ($r_gcountries = mysql_fetch_array($q_gcountries)) { - $gb_country[$i] = $r_gcountries['res_country'] . ";" . $r_gcountries['res_count']; - if ($r_gcountries['res_count'] > $country_max) $country_max = $r_gcountries['res_count']; - $country_sum += $r_gcountries['res_count']; - $i++; + $gb_country[$i] = $r_gcountries['res_country'] . ";" . $r_gcountries['res_count']; + if ($r_gcountries['res_count'] > $country_max) $country_max = $r_gcountries['res_count']; + $country_sum += $r_gcountries['res_count']; + $i++; } echo' @@ -226,4 +234,4 @@ echo'
'; -?> \ No newline at end of file +?> -- cgit