Advertisement
MizunoBrasil

Paginacao 29-12-2022

Dec 28th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include('converte_data.php');
  4.  
  5. //As linhas abaixo são a paginação
  6. $pagina = 1;
  7.  
  8. if (isset($_GET['pagina']))
  9. $pagina = filter_input(INPUT_GET, "pagina", FILTER_VALIDATE_INT);
  10.  
  11. if (!$pagina)
  12. $pagina = 1;
  13.  
  14. $limite = 2;
  15.  
  16. $inicio = ($pagina * $limite) - $limite;
  17.  
  18. $con = new PDO("mysql:host=localhost;dbname=album","root","");
  19.  
  20. $registros = $con->query("SELECT COUNT(nome) count FROM imagem")->fetch()["count"];
  21.  
  22. $paginas = ceil($registros / $limite);
  23.  
  24. $result = $con->query("SELECT * FROM imagem ORDER BY nome LIMIT $inicio, $limite")->fetchall();
  25.  
  26. //var_dump($result);
  27.  
  28. ?>
  29. <!DOCTYPE html>
  30. <html lang="pt-br">
  31. <head>
  32. <meta charset="UTF-8">
  33. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  34. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  35. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  36. <link rel="preconnect" href="https://fonts.googleapis.com">
  37. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  38. <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
  39. <link rel="stylesheet" href="css/style.css">
  40. <title>Galeria</title>
  41. </head>
  42. <style>
  43. body {
  44. font-family: 'Poppins', sans-serif;
  45. font-size: 15px;
  46. }
  47. </style>
  48. <body>
  49. <br><br>
  50. <div class="container">
  51.  
  52. <?php foreach ($result as $foto): ?>
  53.  
  54.  
  55. <br><br>
  56. <div class="row">
  57. <?php
  58. $cont = 0;
  59. foreach ($result as $foto) {
  60. $cont++;
  61. ?>
  62. <div class="col-sm-4">
  63. <div class="shadow p-3 mb-5 bg-white rounded">
  64. <?php echo converte_data($foto['data']); ?><br>
  65. <?php echo "".$foto["assunto"]?><br>
  66.  
  67. <!--<img src="<?php echo "./imagens/".$foto["nome"]?>" width="100%" class="img-fluid"><br>-->
  68. <a href="<?php echo $foto["url"]; ?>" target="_blank"><img src="imagens/<?php echo $foto["nome"]; ?>" width="100%" class="img-fluid"></a><br>
  69. <div class="descricao">
  70. <!--<?php echo "".$foto["descricao"]?><br>-->
  71. <?php echo substr(nl2br($foto['descricao']), 0, 43); ?>...
  72. </div>
  73. <!--<?php echo "<a href=". $foto['url'] ." target='_blank'> <b>Acessar</b></a><br>"?>-->
  74. </div>
  75. </div>
  76. <?php
  77. if($cont ==3){
  78. echo "</div>";
  79. echo "<div class='row'>";
  80. $cont = 0;
  81. }
  82. }
  83. ?>
  84.  
  85. </div>
  86.  
  87. <?php endforeach; ?>
  88.  
  89.  
  90.  
  91. <a href="?pagina=1">Primeira</a>
  92.  
  93. <?php if ($pagina>1): ?>
  94. <a href="?pagina=<?=$pagina-1?>"><<</a>
  95. <?php endif; ?>
  96.  
  97. <?=$pagina?>
  98.  
  99. <?php if ($pagina<$paginas): ?>
  100. <a href="?pagina=<?=$pagina+1?>">>></a>
  101.  
  102. <?php endif; ?>
  103.  
  104. <a href="?pagina=<?=$paginas?>">Última</a>
  105.  
  106.  
  107.  
  108. </container>
  109. </body>
  110. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement