Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.59 KB | None | 0 0
  1. <?php
  2. require_once 'init.php';
  3.  
  4. // abre a conexão
  5. $PDO = db_connect();
  6.  
  7. // SQL para contar o total de registros
  8. // A biblioteca PDO possui o método rowCount(), mas ele pode ser impreciso.
  9. // É recomendável usar a função COUNT da SQL
  10. // Veja o Exemplo 2 deste link: http://php.net/manual/pt_BR/pdostatement.rowcount.php
  11. $sql_count = "SELECT COUNT(*) AS total FROM pontuação ORDER BY scoreJogo DESC";
  12.  
  13. // SQL para selecionar os registros
  14. $sql = "SELECT idJogo, nomeJogo, scoreJogo FROM pontuação ORDER BY scoreJogo DESC";
  15.  
  16. // conta o toal de registros
  17. $stmt_count = $PDO->prepare($sql_count);
  18. $stmt_count->execute();
  19. $total = $stmt_count->fetchColumn();
  20.  
  21. // seleciona os registros
  22. $stmt = $PDO->prepare($sql);
  23. $stmt->execute();
  24. ?>
  25. <!doctype html>
  26. <html>
  27.     <head>
  28.      <meta charset="utf-8">
  29.      <title>Rankings</title>
  30.      <link rel="stylesheet" href="estilos.css">
  31.      <link href="https://fonts.googleapis.com/css?family=Saira+Semi+Condensed&display=swap" rel="stylesheet">
  32.      <title>Sistema de Cadastro </title>
  33.     </head>
  34.  
  35.     <body>
  36.  <div class="cabeçalho">
  37.   <a href="index.html"><img id="logo" src="imagens/logo.png"></img></a>
  38.   <a id="rankings" href="rankings.php"> Rankings </a>
  39.  </div>
  40.   <div style="background:black; color:white;">
  41.         <h1 align="center">Rankings</h1>
  42.  
  43.         <?php if ($total > 0): ?>
  44.  
  45.         <table align="center" width="50%" border="1">
  46.             <thead>
  47.                 <tr>
  48.                  <th width="100px">ID</th>
  49.                  <th width="250px">Nome</th>
  50.                  <th width="100px">Pontuação</th>
  51.                  <th width="150px">Ação</th>
  52.                 </tr>
  53.             </thead>
  54.             <tbody>
  55.                 <?php while ($user = $stmt->fetch(PDO::FETCH_ASSOC)): ?>
  56.                 <tr>
  57.                     <td align="center"><?php echo $user['idJogo'] ?></td>
  58.                     <td align="center"><?php echo $user['nomeJogo'] ?></td>
  59.                     <td align="center"><?php echo $user['scoreJogo'] ?></td>
  60.                     <td align="center">
  61.                         <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>
  62.                 </tr>
  63.                 <?php endwhile; ?>
  64.             </tbody>
  65.         </table>
  66.         <p align="center">Total de jogadores: <text style="font-size:30px; color:red;"><?php echo $total ?></text></p>
  67.  
  68.         <?php else: ?>
  69.  
  70.         <p align="center">Nenhum jogador registrado</p>
  71.  
  72.         <?php endif; ?>
  73.     </div>
  74.     </body>
  75. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement