Advertisement
MizunoBrasil

index de galeria de fotos com PDO

Jan 25th, 2023
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.34 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pt-br">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  8.     <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
  9.     <link rel="stylesheet" href="css/style.css">
  10.     <title>Galeria de imagens</title>
  11. </head>
  12. <style>
  13.     body {
  14.     font-family: 'Poppins', sans-serif;
  15.     font-size: 15px;
  16.     }
  17.     </style>
  18. <body>
  19.     <br>
  20.     <div class="container">
  21.         <h4>Listagem de fotos</h4>
  22.         <a href="form_upload.php">Subir imagem</a> | <a href="form_search.php">Pesquisar imagem</a>
  23.         <br><br><br>
  24.  
  25.       <div class="row">
  26.   <?php
  27.   $pdo = new PDO('mysql:host=______;dbname=__________', 'usuario', 'senha');
  28.   $stmt = $pdo->prepare("SELECT id, name, arquivo FROM tabimagem ORDER BY id DESC");
  29.   $stmt->execute();
  30.   $images = $stmt->fetchAll();
  31.   $i = 0;
  32.   $total_images = count($images);
  33.   $current_page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  34.   $images_per_page = 12;
  35.   $total_pages = ceil($total_images / $images_per_page);
  36.   $start = ($current_page - 1) * $images_per_page;
  37.   $images = array_slice($images, $start, $images_per_page);
  38.   foreach($images as $image):
  39.   ?>
  40.     <div class="col-12 col-md-3">
  41.         <div class="shadow p-3 mb-5 bg-white rounded">
  42.             <!--<img src="<?php echo $image['arquivo']; ?>" class="img-fluid">-->
  43.             <a href="<?php echo  $image["arquivo"]; ?>" target="_blank"><img src="<?php echo  $image["arquivo"]; ?>" width="100%" class="img-fluid"></a>
  44.             <?php echo $image['name']; ?>
  45.         </div>  
  46.     </div>
  47.   <?php
  48.     $i++;
  49.     if($i % 12 == 0 && $i != 0){
  50.       echo '</div><div class="row">';
  51.     }
  52.   endforeach;
  53.   ?>
  54. </div>
  55. <div class="text-center">
  56.   <ul class="pagination">
  57.     <?php for($i = 1; $i <= $total_pages; $i++): ?>
  58.       <li class="page-item <?php if($current_page == $i) echo 'active'; ?>">
  59.         <a class="page-link" href="index.php?page=<?php echo $i; ?>"><?php echo $i; ?></a>
  60.       </li>
  61.     <?php endfor; ?>
  62.   </ul>
  63. </div>
  64.     </div>
  65.          <div class="rodape-site">
  66.       Mizuno © 2023
  67.   </div>  
  68.     </body>
  69.     </html>    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement