Problème décomposer un site en php avec pagination

Par elfefe, il y a 10 ans


Bonjour,
J'ai un soucis avec la pagination, je ne sais pas comment faire pour que mes pages de livre d'or s'affichent.
Quand je clic sur mes pages j'ai ma page 404 qui s'affiche.
dans mon url j'ai

index.php

<?php session_start(); // Instance PDO try { $PDO = new PDO('mysql:host=localhost;dbname=fefe_sco','root',''); $PDO->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING); $PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_OBJ); } catch(PDOExeption $e) { echo 'Connexion impossible'; } // Class Auth require "includes/class.auth.php"; if(!isset($_GET['p'])){$_GET['p']="home";} if(!file_exists("content/".$_GET['p'].".php")){$_GET['p']="404";} ob_start(); include "content/".$_GET['p'].".php"; $_content_for_layout=ob_get_contents(); ob_end_clean(); ?> <?php include('includes/header.php'); ?> <?php include('includes/nav.php'); ?> <section> <?php echo $_content_for_layout; ?> <!--<h1>SESSION</h1> <pre><?php /*print_r($_SESSION);*/ ?></pre>--> </section> <?php include('includes/footer.php'); ?>

livreor.php

<?php $messageParPage = 2; $messageTotalsReq = $PDO->query('SELECT id FROM livreor'); $messageTotales = $messageTotalsReq->rowCount(); $pagesTotales = ceil($messageTotales/$messageParPage); if(isset($_GET['np']) AND !empty($_GET['np']) AND $_GET['np'] > 0){ $_GET['np'] = intval($_GET['np']); $pageCourante = $_GET['np']; } else { $pageCourante = 1; } $depart = ($pageCourante-1)*$messageParPage; $select = $PDO->prepare('SELECT pseudo, message, role_id, DATE_FORMAT(date, "%d-%m-%Y") AS datefr FROM livreor ORDER BY date DESC LIMIT '.$depart.','.$messageParPage.''); $select->execute(); while($users = $select->fetch(PDO::FETCH_OBJ)){ if($users->role_id == 1){ ?> <div class="oval-admin"> <p class="pseudo"><?php echo $users->pseudo; ?> <span class="date"><?php echo $users->datefr; ?></span></p> <p><?php echo $users->message; ?></p> </div> <?php }else{?> <div class="oval-member"> <p class="pseudo"><?php echo $users->pseudo; ?> <span class="date"><?php echo $users->datefr; ?></span></p> <p><?php echo $users->message; ?></p> </div> <?php } }; ?> </article> <?php for($i=1;$i<=$pagesTotales;$i++){ if($i == $pageCourante){ echo $i.' '; } else { echo '<a href="index.php?p=livreor'.$i.'">'.$i.'</a> '; } } ?>

Merci pour votre aide.

11 réponses

AlexJM, il y a 10 ans

Bonsoir,

index.php?p=livreor cette page-ci, fonctionne-t-elle ?

elfefe, il y a 10 ans

Oui elle fonctionne, c'est la seul.

Merci d'avance.

Carouge10, il y a 10 ans

Bonsoir, il vous faut renseigner ensuite le np pour avoir la pagination
index.php?p=livreor&np=2

elfefe, il y a 10 ans

Non ca apprait comme ça
index.php?P=livreor2

AlexJM, il y a 10 ans

après ca,

if(!file_exists("content/".$_GET['p'].".php")){$_GET['p']="404";}

essaye ceci:

elseif(preg_match('^livreor([1-9][0-9]*)$', $_GET['p'], $matches){$_GET['p']='livreor'; $_GET['np']=$matches[1];}
elfefe, il y a 10 ans

Salut AlexJM,
malheureusement, ça ne fonctionne pas, j'ai toujours la même chose.
Merci d'avance.

AlexJM, il y a 10 ans

peux-tu faire var_dump($_GET); juste après le elseif et nous en donner le résultat stp ? :)

elfefe, il y a 10 ans

j'ai ce résultat

array(1) { ["p"]=> string(7) "livreor" }
AlexJM, il y a 10 ans

et quand tu vas sur livreor2

elfefe, il y a 10 ans

livreor2 j'ai ça

array(1) { ["p"]=> string(3) "404" }
elfefe, il y a 10 ans

j'ai trouvé mon erreur, cela venait de mon fichier livreor.php, j'ai rajouté mon paramètre dans mon echo :
avant :

<?php for($i=1;$i<=$pagesTotales;$i++){ if($i == $pageCourante){ echo $i.' '; } else { echo '<a href="index.php?p=livreor'.$i.'">'.$i.'</a> '; } } ?>

après :

<?php for($i=1;$i<=$pagesTotales;$i++){ if($i == $pageCourante){ echo $i.' '; } else { echo '<a href="index.php?p=livreor&np='.$i.'">'.$i.'</a> '; } } ?>

encore merci à tous pour votre aide.