Skip to content

Commit 66b162b

Browse files
authored
Merge pull request #3 from sn3p/sn3p/fix-mysql-group-by-errors
Fix MySQL ONLY_FULL_GROUP_BY errors
2 parents 07b6b55 + 7abeb20 commit 66b162b

File tree

8 files changed

+243
-204
lines changed

8 files changed

+243
-204
lines changed

html/pages/graph_mbreakdown.php

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,32 @@
33

44
// Hourly Breakdown
55
$sql_ghours = "SELECT HOUR(time) AS res_hour, COUNT(*) AS res_count
6-
FROM uts_match WHERE $bgwhere GROUP by res_hour";
6+
FROM uts_match
7+
WHERE $bgwhere
8+
GROUP by res_hour";
79
$q_ghours = mysql_query($sql_ghours) or die(mysql_error());
810
$hour_max = 0;
911
$hour_sum = 0;
1012
while ($r_ghours = mysql_fetch_array($q_ghours)) {
11-
$gb_hour[$r_ghours['res_hour']] = $r_ghours['res_count'];
12-
if ($r_ghours['res_count'] > $hour_max) $hour_max = $r_ghours['res_count'];
13-
$hour_sum += $r_ghours['res_count'];
13+
$gb_hour[$r_ghours['res_hour']] = $r_ghours['res_count'];
14+
if ($r_ghours['res_count'] > $hour_max) $hour_max = $r_ghours['res_count'];
15+
$hour_sum += $r_ghours['res_count'];
1416
}
1517
if ($hour_max == 0) return;
1618

1719
// Daily Breakdown
1820
// We use WEEKDAY rather then DAYOFWEEK because now the week starts with Monday instead of Sunday
1921
$sql_gdays = "SELECT WEEKDAY(time) AS res_day, COUNT(*) AS res_count
20-
FROM uts_match WHERE $bgwhere GROUP by res_day";
22+
FROM uts_match
23+
WHERE $bgwhere
24+
GROUP by res_day";
2125
$q_gdays = mysql_query($sql_gdays) or die(mysql_error());
2226
$day_max = 0;
2327
$day_sum = 0;
2428
while ($r_gdays = mysql_fetch_array($q_gdays)) {
25-
$gb_day[$r_gdays['res_day']] = $r_gdays['res_count'];
26-
if ($r_gdays['res_count'] > $day_max) $day_max = $r_gdays['res_count'];
27-
$day_sum += $r_gdays['res_count'];
29+
$gb_day[$r_gdays['res_day']] = $r_gdays['res_count'];
30+
if ($r_gdays['res_count'] > $day_max) $day_max = $r_gdays['res_count'];
31+
$day_sum += $r_gdays['res_count'];
2832
}
2933

3034
// Monthly Breakdown
@@ -34,9 +38,9 @@
3438
$month_max = 0;
3539
$month_sum = 0;
3640
while ($r_gmonths = mysql_fetch_array($q_gmonths)) {
37-
$gb_month[$r_gmonths['res_month']] = $r_gmonths['res_count'];
38-
if ($r_gmonths['res_count'] > $month_max) $month_max = $r_gmonths['res_count'];
39-
$month_sum += $r_gmonths['res_count'];
41+
$gb_month[$r_gmonths['res_month']] = $r_gmonths['res_count'];
42+
if ($r_gmonths['res_count'] > $month_max) $month_max = $r_gmonths['res_count'];
43+
$month_sum += $r_gmonths['res_count'];
4044
}
4145

4246
// very dirty hack, to deal with the $bgwhere containing an OR
@@ -54,19 +58,23 @@
5458
}
5559

5660
// Country Breakdown
57-
$sql_gcountries = "SELECT country AS res_country, COUNT(*) AS res_count FROM
58-
(SELECT p.country AS country FROM uts_player AS p, uts_match AS m
59-
WHERE m.id = p.matchid AND $bgwhere GROUP BY p.pid) AS res_table
60-
GROUP BY res_country ORDER BY res_count DESC";
61+
$sql_gcountries = "SELECT country AS res_country, COUNT(*) AS res_count
62+
FROM (SELECT p.country AS country
63+
FROM uts_player AS p, uts_match AS m
64+
WHERE m.id = p.matchid AND $bgwhere
65+
GROUP BY p.pid, p.country) AS res_table
66+
GROUP BY res_country
67+
ORDER BY res_count DESC";
68+
6169
$q_gcountries = mysql_query($sql_gcountries) or die(mysql_error());
6270
$country_max = 0;
6371
$country_sum = 0;
6472
$i = 0;
6573
while ($r_gcountries = mysql_fetch_array($q_gcountries)) {
66-
$gb_country[$i] = $r_gcountries['res_country'] . ";" . $r_gcountries['res_count'];
67-
if ($r_gcountries['res_count'] > $country_max) $country_max = $r_gcountries['res_count'];
68-
$country_sum += $r_gcountries['res_count'];
69-
$i++;
74+
$gb_country[$i] = $r_gcountries['res_country'] . ";" . $r_gcountries['res_count'];
75+
if ($r_gcountries['res_count'] > $country_max) $country_max = $r_gcountries['res_count'];
76+
$country_sum += $r_gcountries['res_count'];
77+
$i++;
7078
}
7179

7280
echo'
@@ -226,4 +234,4 @@
226234
</tbody>
227235
</table>
228236
<br>';
229-
?>
237+
?>

html/pages/home.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@
5757
</tr>';
5858

5959
$sql_gamesummary = "SELECT g.id AS gid, g.name AS gamename, SUM(p.frags) AS frags, SUM(p.kills) AS kills, SUM(p.suicides) AS suicides, SUM(p.teamkills) AS teamkills, COUNT(DISTINCT p.matchid) AS matchcount
60-
FROM uts_player AS p, uts_games AS g WHERE p.gid = g.id GROUP BY gamename ORDER BY gamename ASC";
60+
FROM uts_player AS p, uts_games AS g
61+
WHERE p.gid = g.id
62+
GROUP BY gamename, gid
63+
ORDER BY gamename ASC";
64+
6165
$q_gamesummary = mysql_query($sql_gamesummary) or die(mysql_error());
62-
while ($r_gamesummary = mysql_fetch_array($q_gamesummary)) {
6366

67+
while ($r_gamesummary = mysql_fetch_array($q_gamesummary)) {
6468
$gid = $r_gamesummary[gid];
6569

6670
$q_gametime = small_query("SELECT SUM(gametime) AS gametime FROM uts_match WHERE gid = '$gid'");
@@ -76,7 +80,8 @@
7680
}
7781

7882
$totalsummary = small_query("SELECT SUM(p.frags) AS frags, SUM(p.kills) AS kills, SUM(p.suicides) AS suicides, SUM(p.teamkills) AS teamkills, COUNT(DISTINCT p.matchid) AS matchcount, SUM(p.gametime) AS gametime
79-
FROM uts_player AS p, uts_games AS g WHERE p.gid = g.id");
83+
FROM uts_player AS p, uts_games AS g
84+
WHERE p.gid = g.id");
8085

8186
$q_gametime = small_query("SELECT SUM(gametime) AS gametime FROM uts_match");
8287
$gametime = sec2hour($q_gametime[gametime]);
@@ -97,4 +102,4 @@
97102
$gtitle = "Across All Servers";
98103
$bgwhere = "id >= 0";
99104
include("pages/graph_mbreakdown.php");
100-
?>
105+
?>

html/pages/match.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
$mid = preg_replace('/\D/', '', $_GET[mid]);
33
$pid = preg_replace('/\D/', '', $_GET[pid]);
44

5-
IF ($pid != "") {
5+
if ($pid != "") {
66
include("match_player.php");
77
} else {
88
include("match_info.php");
99
}
10-
?>
10+
?>

html/pages/match_info.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
case "Assault (insta)":
2424
include("pages/match_info_ass.php");
2525
break;
26-
26+
2727
case "Capture the Flag":
2828
case "Capture the Flag (insta)":
2929
include("pages/match_info_ctf.php");
3030
teamstats($mid, 'Match Summary');
3131
break;
32-
32+
3333
case "Domination":
3434
case "Domination (insta)":
3535
teamstats($mid, 'Match Summary', 'dom_cp', 'Dom Pts');
3636
break;
37-
37+
3838
case "JailBreak":
3939
case "JailBreak (insta)":
4040
teamstats($mid, 'Match Summary', 'ass_obj', 'Team Releases');
@@ -62,7 +62,6 @@
6262
teamstats($mid, 'Player Summary');
6363
}
6464
}
65-
6665

6766
if ($real_gamename == "Assault" or $real_gamename== "Assault (insta)") {
6867
include("pages/match_info_other2.php");
@@ -75,4 +74,4 @@
7574
include("pages/match_report.php");
7675
}
7776

78-
?>
77+
?>

html/pages/match_info_other.php

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,33 @@
1010
<td class="heading" colspan="11" align="center">Special Events</td>
1111
</tr>
1212
<tr>
13-
<td class="smheading" align="center" rowspan="2" width="">Player</td>
14-
<td class="smheading" align="center" rowspan="2" width="60">First Blood</td>
15-
<td class="smheading" align="center" colspan="4" width="160" '.OverlibPrintHint('Multis').'>Multis</td>
16-
<td class="smheading" align="center" colspan="5" width="200" '.OverlibPrintHint('Sprees').'>Sprees</td>
13+
<td class="smheading" align="center" rowspan="2" width="">Player</td>
14+
<td class="smheading" align="center" rowspan="2" width="60">First Blood</td>
15+
<td class="smheading" align="center" colspan="4" width="160" '.OverlibPrintHint('Multis').'>Multis</td>
16+
<td class="smheading" align="center" colspan="5" width="200" '.OverlibPrintHint('Sprees').'>Sprees</td>
1717
</tr>
1818
<tr>
19-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('DK').'>Dbl</td>
20-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('MK').'>Multi</td>
21-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('UK').'>Ultra</td>
22-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('MOK').'>Mons</td>
23-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('KS').'>Kill</td>
24-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('RA').'>Ram</td>
25-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('DO').'>Dom</td>
26-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('US').'>Uns</td>
27-
<td class="smheading" align="center" width="40" '.OverlibPrintHint('GL').'>God</td>
19+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('DK').'>Dbl</td>
20+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('MK').'>Multi</td>
21+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('UK').'>Ultra</td>
22+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('MOK').'>Mons</td>
23+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('KS').'>Kill</td>
24+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('RA').'>Ram</td>
25+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('DO').'>Dom</td>
26+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('US').'>Uns</td>
27+
<td class="smheading" align="center" width="40" '.OverlibPrintHint('GL').'>God</td>
2828
</tr>';
29+
2930
$sql_firstblood = small_query("SELECT firstblood FROM uts_match WHERE id = $mid");
3031
$sql_multis = "SELECT p.pid, pi.name, p.country, SUM(spree_double) AS spree_double, SUM(spree_multi) AS spree_multi,
3132
SUM(spree_ultra) AS spree_ultra, SUM(spree_monster) AS spree_monster,
3233
SUM(spree_kill) AS spree_kill, SUM(spree_rampage) AS spree_rampage, SUM(spree_dom) AS spree_dom,
3334
SUM(spree_uns) AS spree_uns, SUM(spree_god) AS spree_god
34-
FROM uts_player as p, uts_pinfo AS pi WHERE p.pid = pi.id AND pi.banned <> 'Y' AND matchid = $mid GROUP BY pid ORDER BY name ASC";
35+
FROM uts_player as p, uts_pinfo AS pi
36+
WHERE p.pid = pi.id AND pi.banned <> 'Y' AND matchid = $mid
37+
GROUP BY pid, p.country
38+
ORDER BY name ASC";
39+
3540
$q_multis = mysql_query($sql_multis) or die(mysql_error());
3641
$i = 0;
3742
while ($r_multis = zero_out(mysql_fetch_array($q_multis))) {
@@ -42,17 +47,17 @@
4247

4348
echo'
4449
<tr>
45-
<td nowrap class="darkhuman" align="left"><a class="darkhuman" href="./?p=matchp&amp;mid='.$mid.'&amp;pid='.$r_multis['pid'].'">'.FormatPlayerName($r_multis[country], $r_multis[pid], $r_pname, $gid, $gamename).'</a></td>
46-
<td class="'.$class.'" align="center">', ($sql_firstblood['firstblood'] == $r_multis['pid'] ? "Yes": ""), '</td>
47-
<td class="'.$class.'" align="center">'.$r_multis[spree_double].'</td>
48-
<td class="'.$class.'" align="center">'.$r_multis[spree_multi].'</td>
49-
<td class="'.$class.'" align="center">'.$r_multis[spree_ultra].'</td>
50-
<td class="'.$class.'" align="center">'.$r_multis[spree_monster].'</td>
51-
<td class="'.$class.'" align="center">'.$r_multis[spree_kill].'</td>
52-
<td class="'.$class.'" align="center">'.$r_multis[spree_rampage].'</td>
53-
<td class="'.$class.'" align="center">'.$r_multis[spree_dom].'</td>
54-
<td class="'.$class.'" align="center">'.$r_multis[spree_uns].'</td>
55-
<td class="'.$class.'" align="center">'.$r_multis[spree_god].'</td>
50+
<td nowrap class="darkhuman" align="left"><a class="darkhuman" href="./?p=matchp&amp;mid='.$mid.'&amp;pid='.$r_multis['pid'].'">'.FormatPlayerName($r_multis[country], $r_multis[pid], $r_pname, $gid, $gamename).'</a></td>
51+
<td class="'.$class.'" align="center">', ($sql_firstblood['firstblood'] == $r_multis['pid'] ? "Yes": ""), '</td>
52+
<td class="'.$class.'" align="center">'.$r_multis[spree_double].'</td>
53+
<td class="'.$class.'" align="center">'.$r_multis[spree_multi].'</td>
54+
<td class="'.$class.'" align="center">'.$r_multis[spree_ultra].'</td>
55+
<td class="'.$class.'" align="center">'.$r_multis[spree_monster].'</td>
56+
<td class="'.$class.'" align="center">'.$r_multis[spree_kill].'</td>
57+
<td class="'.$class.'" align="center">'.$r_multis[spree_rampage].'</td>
58+
<td class="'.$class.'" align="center">'.$r_multis[spree_dom].'</td>
59+
<td class="'.$class.'" align="center">'.$r_multis[spree_uns].'</td>
60+
<td class="'.$class.'" align="center">'.$r_multis[spree_god].'</td>
5661
</tr>';
5762
}
5863

@@ -75,7 +80,11 @@
7580

7681
$sql_pickups = "SELECT p.pid, pi.name, p.country, SUM(p.pu_pads) AS pu_pads, SUM(p.pu_armour) AS pu_armour, SUM(p.pu_keg) AS pu_keg,
7782
SUM(p.pu_invis) AS pu_invis, SUM(p.pu_belt) AS pu_belt, SUM(p.pu_amp) AS pu_amp
78-
FROM uts_player as p, uts_pinfo AS pi WHERE p.pid = pi.id AND pi.banned <> 'Y' AND matchid = $mid GROUP BY pid ORDER BY name ASC";
83+
FROM uts_player as p, uts_pinfo AS pi
84+
WHERE p.pid = pi.id AND pi.banned <> 'Y' AND matchid = $mid
85+
GROUP BY pid, p.country
86+
ORDER BY name ASC";
87+
7988
$q_pickups = mysql_query($sql_pickups) or die(mysql_error());
8089
$i = 0;
8190
while ($r_pickups = zero_out(mysql_fetch_array($q_pickups))) {

0 commit comments

Comments
 (0)