Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include('converte_data.php');
- $banco = new mysqli("localhost", "root", "", "album");
- $sql = "SELECT * FROM imagem ORDER BY id DESC";
- $resultado = $banco->query($sql);
- while ($linha = mysqli_fetch_array($resultado)) {
- $album[] = $linha;
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>PHP Pagination</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- </head>
- <body>
- <?php
- $limit = 4; // Number of entries to show in a page.
- // Look for a GET variable page if not found default is 1.
- if (isset($_GET["page"])) {
- $pn = $_GET["page"];
- } else {
- $pn = 1;
- };
- $start_from = ($pn - 1) * $limit;
- $sql = "SELECT * FROM imagem LIMIT $start_from, $limit";
- $rs_result = $banco->query($sql);
- ?>
- <div class="container">
- <br>
- <div>
- <h1>PHP Pagination Using MySQLi</h1>
- <p>This page is just for demonstration of Basic Pagination using PHP.</p>
- <table class="table table-striped table-condensed table-bordered">
- <thead>
- <tr>
- <th width="10%">Assunto</th>
- <th>Nome/Foto</th>
- </tr>
- </thead>
- <tbody>
- <?php
- while ($row = $rs_result->fetch_assoc()) {
- // Display each field of the records.
- ?>
- <!-- <tr>
- <td><?php echo $row["assunto"]; ?></td>
- <td><a href="<?php echo $row["url"]; ?>" target="_blank"><img src="imagens/<?php echo $row["nome"]; ?>" width="100%" class="img-fluid"></a></td>
- </tr> -->
- <!-- <tr>
- <td><?php echo $row["assunto"]; ?></td>
- <td><a href="<?php echo $row["url"]; ?>" target="_blank"><img src="imagens/<?php echo $row["nome"]; ?>" width="100%" class="img-fluid"></a></td>
- <td><?php echo $row["assunto"]; ?></td>
- <td><a href="<?php echo $row["url"]; ?>" target="_blank"><img src="imagens/<?php echo $row["nome"]; ?>" width="100%" class="img-fluid"></a></td>
- </tr> -->
- <div class="row">
- <div class="col-sm-6">
- <div class="shadow-sm p-3 mb-5 bg-white rounded">
- <img src="imagens/<?php echo $row["nome"]; ?>" class="img-fluid" width="100%">
- <!-- <a href="#" target="_blank">Titulo da Imagem</a> -->
- </div>
- </div>
- <?php
- };
- ?>
- </div>
- </tbody>
- </table>
- <ul class="pagination">
- <?php
- $sql = "SELECT COUNT(*) FROM imagem";
- $rs_result = $banco->query($sql);
- $row = mysqli_fetch_row($rs_result);
- $total_records = $row[0];
- // Number of pages required.
- $total_pages = ceil($total_records / $limit);
- $pagLink = "";
- for ($i = 1; $i <= $total_pages; $i++) {
- if ($i == $pn) {
- $pagLink .= "<li class='active'><a href='lista.php?page="
- . $i . "'>" . $i . "</a></li>";
- } else {
- $pagLink .= "<li><a href='lista.php?page=" . $i . "'>
- " . $i . "</a></li>";
- }
- };
- echo $pagLink;
- ?>
- </ul>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement