Skip to content

Commit

Permalink
Merge pull request #3 from sn3p/sn3p/fix-mysql-group-by-errors
Browse files Browse the repository at this point in the history
Fix MySQL ONLY_FULL_GROUP_BY errors
  • Loading branch information
sn3p authored Feb 12, 2017
2 parents 07b6b55 + 7abeb20 commit 66b162b
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 204 deletions.
48 changes: 28 additions & 20 deletions html/pages/graph_mbreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@

// 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
Expand All @@ -34,9 +38,9 @@
$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
Expand All @@ -54,19 +58,23 @@
}

// 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'
Expand Down Expand Up @@ -226,4 +234,4 @@
</tbody>
</table>
<br>';
?>
?>
13 changes: 9 additions & 4 deletions html/pages/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@
</tr>';

$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
FROM uts_player AS p, uts_games AS g WHERE p.gid = g.id GROUP BY gamename ORDER BY gamename ASC";
FROM uts_player AS p, uts_games AS g
WHERE p.gid = g.id
GROUP BY gamename, gid
ORDER BY gamename ASC";

$q_gamesummary = mysql_query($sql_gamesummary) or die(mysql_error());
while ($r_gamesummary = mysql_fetch_array($q_gamesummary)) {

while ($r_gamesummary = mysql_fetch_array($q_gamesummary)) {
$gid = $r_gamesummary[gid];

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

$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
FROM uts_player AS p, uts_games AS g WHERE p.gid = g.id");
FROM uts_player AS p, uts_games AS g
WHERE p.gid = g.id");

$q_gametime = small_query("SELECT SUM(gametime) AS gametime FROM uts_match");
$gametime = sec2hour($q_gametime[gametime]);
Expand All @@ -97,4 +102,4 @@
$gtitle = "Across All Servers";
$bgwhere = "id >= 0";
include("pages/graph_mbreakdown.php");
?>
?>
4 changes: 2 additions & 2 deletions html/pages/match.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
$mid = preg_replace('/\D/', '', $_GET[mid]);
$pid = preg_replace('/\D/', '', $_GET[pid]);

IF ($pid != "") {
if ($pid != "") {
include("match_player.php");
} else {
include("match_info.php");
}
?>
?>
9 changes: 4 additions & 5 deletions html/pages/match_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
case "Assault (insta)":
include("pages/match_info_ass.php");
break;

case "Capture the Flag":
case "Capture the Flag (insta)":
include("pages/match_info_ctf.php");
teamstats($mid, 'Match Summary');
break;

case "Domination":
case "Domination (insta)":
teamstats($mid, 'Match Summary', 'dom_cp', 'Dom Pts');
break;

case "JailBreak":
case "JailBreak (insta)":
teamstats($mid, 'Match Summary', 'ass_obj', 'Team Releases');
Expand Down Expand Up @@ -62,7 +62,6 @@
teamstats($mid, 'Player Summary');
}
}


if ($real_gamename == "Assault" or $real_gamename== "Assault (insta)") {
include("pages/match_info_other2.php");
Expand All @@ -75,4 +74,4 @@
include("pages/match_report.php");
}

?>
?>
61 changes: 35 additions & 26 deletions html/pages/match_info_other.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,33 @@
<td class="heading" colspan="11" align="center">Special Events</td>
</tr>
<tr>
<td class="smheading" align="center" rowspan="2" width="">Player</td>
<td class="smheading" align="center" rowspan="2" width="60">First Blood</td>
<td class="smheading" align="center" colspan="4" width="160" '.OverlibPrintHint('Multis').'>Multis</td>
<td class="smheading" align="center" colspan="5" width="200" '.OverlibPrintHint('Sprees').'>Sprees</td>
<td class="smheading" align="center" rowspan="2" width="">Player</td>
<td class="smheading" align="center" rowspan="2" width="60">First Blood</td>
<td class="smheading" align="center" colspan="4" width="160" '.OverlibPrintHint('Multis').'>Multis</td>
<td class="smheading" align="center" colspan="5" width="200" '.OverlibPrintHint('Sprees').'>Sprees</td>
</tr>
<tr>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('DK').'>Dbl</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('MK').'>Multi</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('UK').'>Ultra</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('MOK').'>Mons</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('KS').'>Kill</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('RA').'>Ram</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('DO').'>Dom</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('US').'>Uns</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('GL').'>God</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('DK').'>Dbl</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('MK').'>Multi</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('UK').'>Ultra</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('MOK').'>Mons</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('KS').'>Kill</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('RA').'>Ram</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('DO').'>Dom</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('US').'>Uns</td>
<td class="smheading" align="center" width="40" '.OverlibPrintHint('GL').'>God</td>
</tr>';

$sql_firstblood = small_query("SELECT firstblood FROM uts_match WHERE id = $mid");
$sql_multis = "SELECT p.pid, pi.name, p.country, SUM(spree_double) AS spree_double, SUM(spree_multi) AS spree_multi,
SUM(spree_ultra) AS spree_ultra, SUM(spree_monster) AS spree_monster,
SUM(spree_kill) AS spree_kill, SUM(spree_rampage) AS spree_rampage, SUM(spree_dom) AS spree_dom,
SUM(spree_uns) AS spree_uns, SUM(spree_god) AS spree_god
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";
FROM uts_player as p, uts_pinfo AS pi
WHERE p.pid = pi.id AND pi.banned <> 'Y' AND matchid = $mid
GROUP BY pid, p.country
ORDER BY name ASC";

$q_multis = mysql_query($sql_multis) or die(mysql_error());
$i = 0;
while ($r_multis = zero_out(mysql_fetch_array($q_multis))) {
Expand All @@ -42,17 +47,17 @@

echo'
<tr>
<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>
<td class="'.$class.'" align="center">', ($sql_firstblood['firstblood'] == $r_multis['pid'] ? "Yes": ""), '</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_double].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_multi].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_ultra].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_monster].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_kill].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_rampage].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_dom].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_uns].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_god].'</td>
<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>
<td class="'.$class.'" align="center">', ($sql_firstblood['firstblood'] == $r_multis['pid'] ? "Yes": ""), '</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_double].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_multi].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_ultra].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_monster].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_kill].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_rampage].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_dom].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_uns].'</td>
<td class="'.$class.'" align="center">'.$r_multis[spree_god].'</td>
</tr>';
}

Expand All @@ -75,7 +80,11 @@

$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,
SUM(p.pu_invis) AS pu_invis, SUM(p.pu_belt) AS pu_belt, SUM(p.pu_amp) AS pu_amp
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";
FROM uts_player as p, uts_pinfo AS pi
WHERE p.pid = pi.id AND pi.banned <> 'Y' AND matchid = $mid
GROUP BY pid, p.country
ORDER BY name ASC";

$q_pickups = mysql_query($sql_pickups) or die(mysql_error());
$i = 0;
while ($r_pickups = zero_out(mysql_fetch_array($q_pickups))) {
Expand Down
Loading

0 comments on commit 66b162b

Please sign in to comment.