Skip to content

Commit

Permalink
Fixes SQL query to show Hunting z Highscores
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveratgithub committed Feb 24, 2024
1 parent 4c37227 commit c3c3add
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions www/scripts/hz_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@

$usr_e = $db->query(
"SELECT d.*, concat(u.clan_tag, u.username) username, count(g.id) games, count(if(p.type='z', '1', NULL)) zgames
FROM hz_players p, hz_games g, user u, hz_dwz d WHERE g.id=p.game AND g.state='finished' AND u.id=p.user AND d.user=p.user
FROM hz_players p, hz_games g, user u, hz_dwz d
WHERE g.id=p.game AND g.state='finished' AND u.id=p.user AND d.user=p.user
GROUP BY p.user ORDER BY d.rank", __FILE__, __LINE__, 'SELECT Finished Games Stats'
);
$stats = array();
while ($usr = $db->fetch($usr_e))
{
/** Wins + Loose by User */
$e = $db->query(
"SELECT if(g.z_score > sum(a.score)-g.z_score && p.type='z' || g.z_score < sum(a.score)-g.z_score && p.type!='z', '1', '0') win
FROM hz_players p, hz_games g, hz_aims a WHERE g.id=p.game AND a.map=g.map AND g.state='finished' AND p.user=? GROUP BY g.id HAVING win='1'",
__FILE__, __LINE__, 'SELECT User Wins+Looses', [$usr['user']]
"SELECT CASE WHEN (g.z_score > sum(a.score)-g.z_score AND p.type='z') OR (g.z_score < sum(a.score)-g.z_score AND p.type!='z') THEN '1' ELSE '0' END win
FROM hz_players p, hz_games g, hz_aims a WHERE g.id=p.game AND a.map=g.map AND g.state='finished' AND p.user=? GROUP BY g.id, p.type HAVING win='1'",
__FILE__, __LINE__, 'SELECT User Wins+Looses', [intval($usr['user'])]
);
$usr['win'] = $db->num($e);
$usr['loose'] = $usr['games'] - $usr['win'];


if ($usr['zgames'] != 0) {
$e = $db->query(
"SELECT if(g.z_score > sum(a.score)-g.z_score && p.type='z', '1', '0') win FROM hz_players p, hz_games g, hz_aims a
WHERE g.id=p.game AND a.map=g.map AND g.state='finished' AND p.user=? GROUP BY g.id HAVING win='1'",
"SELECT CASE WHEN (g.z_score > sum(a.score)-g.z_score AND p.type='z') THEN '1' ELSE '0' END win
FROM hz_players p, hz_games g, hz_aims a
WHERE g.id=p.game AND a.map=g.map AND g.state='finished' AND p.user=? GROUP BY g.id, p.type HAVING win='1'",
__FILE__, __LINE__, 'SELECT User Wins as MrZ', [$usr['user']]
);
$usr['zwin'] = $db->num($e);
Expand All @@ -40,8 +42,9 @@
$usr['igames'] = $usr['games'] - $usr['zgames'];
if ($usr['igames'] != 0) {
$e = $db->query(
"SELECT if(g.z_score < sum(a.score)-g.z_score && p.type!='z', '1', '0') win FROM hz_players p, hz_games g, hz_aims a
WHERE g.id=p.game AND a.map=g.map AND g.state='finished' AND p.user=? GROUP BY g.id HAVING win='1'",
"SELECT CASE WHEN (g.z_score < sum(a.score)-g.z_score AND p.type='z') THEN '1' ELSE '0' END win
FROM hz_players p, hz_games g, hz_aims a
WHERE g.id=p.game AND a.map=g.map AND g.state='finished' AND p.user=? GROUP BY g.id, p.type HAVING win='1'",
__FILE__, __LINE__, 'SELECT User Total Wins', [$usr['user']]
);
$usr['iwin'] = $db->num($e);
Expand Down

0 comments on commit c3c3add

Please sign in to comment.