Système de Pagination
Schadd
Messages postés
2
Date d'inscription
Statut
Membre
Dernière intervention
-
yg_be Messages postés 23541 Date d'inscription Statut Contributeur Dernière intervention -
yg_be Messages postés 23541 Date d'inscription Statut Contributeur Dernière intervention -
<?php $bdd = new PDO('mysql:host=localhost:3306; dbname=sprint_b; charset=utf8', 'root', 'root', array(PDO::ATTR_ERRMODE =>PDO::ERRMODE_EXCEPTION)); $articles = $bdd->query('SELECT titre FROM articles ORDER BY id DESC'); if(isset($_GET['q']) AND !empty($_GET['q'])){ $q = htmlspecialchars($_GET['q']); $articles = $bdd->query('SELECT titre FROM articles WHERE titre LIKE "%'.$q.'%" ORDER BY id DESC'); if($articles->rowCount() == 0) { $articles = $bdd->query('SELECT titre FROM articles WHERE CONCAT(titre, contenu) LIKE "%'.$q.'%" ORDER BY id DESC'); } } // Récupérer le nombre d'enregistrements $count=$bdd->prepare("SELECT count(id) AS cpt from articles") ; $count->setFetchMode(PDO::FETCH_ASSOC); $count->execute(); $tcount=$count->fetchAll(); // Pagination @$page=$_GET["page"]; $nbr_elements_par_page=10; $nbr_de_pages = ceil($tcount[0]["cpt"]/$nbr_elements_par_page); $debut=($page-1)*$nbr_elements_par_page; // Récupérer les enregistrements eux-mêmes $sel=$bdd ->prepare ("SELECT titre from articles order by date_time_publication limit $debut,$nbr_elements_par_page"); $sel->setFetchMode (PDO::FETCH_ASSOC); $sel->execute(); $tab=$sel->fetchAll(); ?> <!DOCTYPE html> <html> <head> <title>Accueil</title> <meta charset="utf-8"> <link href="css/bootstrap.min.css" rel="stylesheet"> <style> footer { position: fixed; bottom: 0px; } </style> </head> <body> <br /><br /> <center> <form method="GET"> <input type="search" name="q" placeholder="Recherche..." /> <input type="submit" value="Valider" /> </form> </center> <header> <?php echo $tcount[0]["cpt"] ?> Enregistrement total </header> <br /><br /><br /><br /> <ul> <?php while($a = $articles->fetch()) { ?> <li> <a href="article.php?id=<?= $a['id'] ?>"> <img src="miniatures/<?= $a['id'] ?>.jpg" width="100" /><br /> <?= $a['titre'] ?> </a> | <a href="redaction.php?edit=<?= $a['id'] ?>">Modifier</a> | <a href="supprimer.php?id=<?= $a['id'] ?>">Supprimer</a> </li> <?php } ?> <ul> <?php if($articles->rowCount() > 0) { ?> <ul> <?php while($a = $articles->fetch()) { ?> <li><?= $a['titre'] ?></li> <?php } ?> </ul> <?php } else { ?> Aucun résultat pour: <?= $q ?>... <?php } ?> <footer> <center> <div id="pagination"> <?php for ($i=1;$i<=$nbr_de_pages; $i++) { echo "a href='?page=$i'>$i</a> "; } ?> </div> </center> </footer> </body> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umb/popper.min.js"></script> <script src="js/bootstrap.min.js"></script> </html>
Bonjour, j’ai un problème avec mon code PHP, celui-ci affiche une erreur : la variable $début n’a apparemment pas été initialisé pourtant je l’ai fait à la ligne 12…

Configuration: iPhone / Safari 15.0
A voir également:
- Pagination php pdo
- Pagination powerpoint - Guide
- Easy php - Télécharger - Divers Web & Internet
- Expert php pinterest - Télécharger - Langages
- Sommaire avec pagination - Guide
- Le fichier de pagination est insuffisant pour terminer cette opération ✓ - Forum Matériel & Système
1 réponse
yg_be
Messages postés
23541
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 584
bonjour,
as-tu testé en retirant
as-tu testé en retirant
@de la ligne 19?