Last active
April 13, 2022 21:22
-
-
Save Polsaker/a319eb5ac594526705226c76a5134f95 to your computer and use it in GitHub Desktop.
Donger ranking page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_GET['r'])){ | |
$db = new SQLite3('/home/polsaker/dongerdong/dongerdong.db'); | |
$top_modifier = 0.05; | |
$our_account = "dongerdong"; | |
$stmt = $db->prepare('SELECT * FROM playerstats LIMIT 100 ORDER BY elo DESC;'); | |
$result = $stmt->execute(); | |
$ranks = array(); | |
$r = 1; | |
while($row = $result->fetchArray()){ | |
$fights = $row['matches'] + $row['deathmatches']; | |
if($fights<15){continue;} | |
if($row['nick'] == $our_account){continue;} | |
array_push($ranks, array('nick' => $row['nick'], | |
'score' => $row['elo'], | |
'fites' => $fights, | |
)); | |
} | |
$finalranks = array(); | |
foreach($ranks as $rk){ | |
$rk['rank'] = $r; | |
array_push($finalranks, $rk); | |
$r++; | |
} | |
echo json_encode($finalranks); | |
exit; | |
}?> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Dongerdong ranking</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Dongerdong rankings</h1> | |
<table class="table table-stripped"> | |
<thead> | |
<tr> | |
<th>#</th> | |
<th>Nick</th> | |
<th>Score</th> | |
<th>Fights</th> | |
</tr> | |
</thead> | |
<tbody id="ranks"></tbody> | |
</table> | |
</div> | |
</body> | |
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script> | |
<script> | |
function queryRank(){ | |
$.ajax({ | |
url: "?r=1", | |
dataType: "JSON" | |
}).done(function(msg) { | |
var arrayLength = msg.length; | |
var htm = ""; | |
for (var i = 0; i < arrayLength; i++) { | |
htm = htm + "<tr><td> <b>" + msg[i]['rank'] + "</b></td>"; | |
htm = htm + "<td> " + msg[i]['nick'] + "</td>"; | |
htm = htm + "<td> " + msg[i]['score'] + "</td>"; | |
htm = htm + "<td> " + msg[i]['fites'] + "</td></tr>"; | |
} | |
$("#ranks").html(htm); | |
}); | |
} | |
$( document ).ready(function(){ | |
setInterval(queryRank, 5000); | |
queryRank(); | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment