Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'init.php';
- // abre a conexão
- $PDO = db_connect();
- // SQL para contar o total de registros
- // A biblioteca PDO possui o método rowCount(), mas ele pode ser impreciso.
- // É recomendável usar a função COUNT da SQL
- // Veja o Exemplo 2 deste link: http://php.net/manual/pt_BR/pdostatement.rowcount.php
- $sql_count = "SELECT COUNT(*) AS total FROM pontuação ORDER BY scoreJogo DESC";
- // SQL para selecionar os registros
- $sql = "SELECT idJogo, nomeJogo, scoreJogo FROM pontuação ORDER BY scoreJogo DESC";
- // conta o toal de registros
- $stmt_count = $PDO->prepare($sql_count);
- $stmt_count->execute();
- $total = $stmt_count->fetchColumn();
- // seleciona os registros
- $stmt = $PDO->prepare($sql);
- $stmt->execute();
- ?>
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Rankings</title>
- <link rel="stylesheet" href="estilos.css">
- <link href="https://fonts.googleapis.com/css?family=Saira+Semi+Condensed&display=swap" rel="stylesheet">
- <title>Sistema de Cadastro </title>
- </head>
- <body>
- <div class="cabeçalho">
- <a href="index.html"><img id="logo" src="imagens/logo.png"></img></a>
- <a id="rankings" href="rankings.php"> Rankings </a>
- </div>
- <div style="background:black; color:white;">
- <h1 align="center">Rankings</h1>
- <?php if ($total > 0): ?>
- <table align="center" width="50%" border="1">
- <thead>
- <tr>
- <th width="100px">ID</th>
- <th width="250px">Nome</th>
- <th width="100px">Pontuação</th>
- <th width="150px">Ação</th>
- </tr>
- </thead>
- <tbody>
- <?php while ($user = $stmt->fetch(PDO::FETCH_ASSOC)): ?>
- <tr>
- <td align="center"><?php echo $user['idJogo'] ?></td>
- <td align="center"><?php echo $user['nomeJogo'] ?></td>
- <td align="center"><?php echo $user['scoreJogo'] ?></td>
- <td align="center">
- <a style="color:red; text-decoration:underline;" href="delete.php?id=<?php echo $user['idJogo'] ?>" onclick="return confirm('Tem certeza de que deseja remover?');">Remover </a> </td>
- </tr>
- <?php endwhile; ?>
- </tbody>
- </table>
- <p align="center">Total de jogadores: <text style="font-size:30px; color:red;"><?php echo $total ?></text></p>
- <?php else: ?>
- <p align="center">Nenhum jogador registrado</p>
- <?php endif; ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement