Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Lista de Adultos</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
- </head>
- <body>
- <div class="container">
- <h2>Lista de Adultos</h2>
- <table class="table">
- <thead>
- <tr>
- <th>URL</th>
- <th>Título</th>
- <th>Data</th>
- </tr>
- </thead>
- <tbody>
- <?php
- // Informações de conexão ao banco de dados
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "0000";
- // Conectando ao banco de dados usando PDO
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch(PDOException $e) {
- echo "Falha na conexão: " . $e->getMessage();
- }
- // Configurando a paginação
- $results_per_page = 15;
- if (isset($_GET["page"])) {
- $page = $_GET["page"];
- } else {
- $page = 1;
- }
- $start_from = ($page-1) * $results_per_page;
- // Selecionando registros da tabela usando PDO
- $stmt = $conn->prepare("SELECT url, title, date FROM adulto LIMIT :start_from, :results_per_page");
- $stmt->bindParam(':start_from', $start_from, PDO::PARAM_INT);
- $stmt->bindParam(':results_per_page', $results_per_page, PDO::PARAM_INT);
- $stmt->execute();
- $result = $stmt->fetchAll();
- if ($result) {
- // Exibindo os registros na tabela
- foreach($result as $row) {
- echo "<tr>";
- echo "<td>" . $row["url"] . "</td>";
- echo "<td>" . $row["title"] . "</td>";
- echo "<td>" . $row["date"] . "</td>";
- echo "</tr>";
- }
- } else {
- echo "0 resultados";
- }
- // Exibindo links para navegar pelas páginas
- $stmt = $conn->prepare("SELECT COUNT(*) AS total FROM adulto");
- $stmt->execute();
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- $total_pages = ceil($row["total"] / $results_per_page);
- echo "<nav aria-label='Page navigation example'>";
- echo "<ul class='pagination justify-content-center'>";
- $prev_class = ($page == 1) ? 'disabled' : '';
- echo "<li class='page-item {$prev_class}'><a class='page-link' href='index.php?page=".($page-1)."'>«</a></li>";
- for ($i=1; $i<=$total_pages; $i++) {
- $active_class = ($page == $i) ? 'active' : '';
- echo "<li class='page-item {$active_class}'><a class='page-link' href='index.php?page=".$i."'>".$i."</a></li>";
- }
- $next_class = ($page == $total_pages) ? 'disabled' : '';
- echo "<li class='page-item {$next_class}'><a class='page-link' href='index.php?page=".($page+1)."'>»</a></li>";
- echo "</ul>";
- echo "</nav>";
- // Encerrando a conexão com o banco de dados
- $conn = null;
- ?>
- </tbody>
- </table>
- </div>
- <!-- Bootstrap JS -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement