-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathranking.php
70 lines (60 loc) · 2.92 KB
/
ranking.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8" />
<title> TRABALHO 3 - PHP </title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<header>
<div id="logo">
<img id="tetris-logo" src="img/project-logo.png" alt="logotipo">
</div>
</header>
<section>
<a href="index.php"><button id="button" onclick="historico.php">Voltar ao Jogo</button></a>
<div id="historico">
<div class="title">
<h3>Ranking de Partidas</h3><hr>
<?php
session_start();
if(!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] == false){
echo "Please login first to see this page.";
header("Location: login.php");
}
try{
$conn = new PDO("mysql:host=localhost;dbname=bancophp", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM pontuacao ORDER BY pontos DESC limit 10";
$grava = $conn->prepare($sql);
$grava->execute(array());
$i=0;
while($row = $grava->fetch(PDO::FETCH_ASSOC)) {
$i++;
echo '<ul id="dados">';
echo '<li><b>RANK: </b>'.$i.'<b> Name:</b>'.$row['username_dados'].'<b> points:</b>'.$row['pontos'].'<b> level:</b>'.$row['level'].'<b> Time:</b>'.$row['tempo'].'</li>';
echo '</ul>';
//echo "RANK ".$i.": ".$row['username_dados']." com ".$row['pontos']. " pontos, level " .$row['level']. " completado em ".$row['tempo']. " segundos!<br>";
}
echo "<hr>";
$sql = "SELECT ROW_NUMBER() OVER(ORDER BY pontos DESC, tempo ASC) as linha, username_dados
FROM pontuacao";
$grava = $conn->prepare($sql);
$grava->execute(array());
$position = 1;
while($row = $grava->fetch(PDO::FETCH_ASSOC)){
if($row['username_dados'] == $_SESSION['username']){
echo "A sua melhor classificação é ".$position."° lugar!";
break;
}
$position++;
}
}catch(PDOException $e){
echo "Ocorreu um erro: " . $e->getMessage();
}
?>
</div>
</div>
</section>
</body>
</html>