Pagination d'un forum
Résolu
younesase
Messages postés
80
Date d'inscription
Statut
Membre
Dernière intervention
-
reverb94 Messages postés 106 Date d'inscription Statut Membre Dernière intervention -
reverb94 Messages postés 106 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'ai créer un forum ou j'ai mis plusieurs catégorie et dans chaque catégorie il y a les sujets que l'utilisateur écrit mais mon problème et que si il y a plusieurs sujets dans une catégorie par exemple 100 je veux pas qu'il soient tous dans une pages , c'est pour ça que je veut créer un système de pagination pour mon forum , merci de m'aider
Voila ma la table topics de ma base de donné:
CREATE TABLE 'topics' (
'parent' smallint(6) NOT NULL,
'id' int(11) NOT NULL,
'id2' int(11) NOT NULL,
'title' varchar(256) NOT NULL,
'message' longtext NOT NULL,
'authorid' int(11) NOT NULL,
'timestamp' int(11) NOT NULL,
'timestamp2' int(11) NOT NULL,
PRIMARY KEY ('id','id2')
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
----------------------------------------------------------------------------------
Voila mon code
La page list_topics.php :
<?php
//Cette page permet d'afficher la liste des sujets d'une categorie de forum
include('config.php');
if(isset($_GET['parent']))
{
$id = intval($_GET['parent']);
$dn1 = mysql_fetch_array(mysql_query('select count(c.id) as nb1, c.name,count(t.id) as topics from categories as c left join topics as t on t.parent="'.$id.'" where c.id="'.$id.'" group by c.id'));
if($dn1['nb1']>0)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
<title><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?> - Forum</title>
</head>
<body>
<header>
<?php
include 'header.php';
?>
</header>
<?php
if(isset($_SESSION['username']))
{
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
$nb_new_pm = $nb_new_pm['nb_new_pm'];
?>
<div class="box">
<div class="box_left">
<a href="<?php echo $url_home; ?>">Index du Forum</a> > <a href="list_topics.php?parent=<?php echo $id; ?>"><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>
</div>
<div class="box_right">
<a href="list_pm.php">Vos messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Déconnexion</a>)
</div>
<div class="clean"></div>
</div>
<?php
}
else
{
?>
<div class="box">
<div class="box_left">
<a href="<?php echo $url_home; ?>">Index du Forum</a> > <a href="list_topics.php?parent=<?php echo $id; ?>"><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>
</div>
<div class="box_right">
<a href="signup.php">Inscription</a> - <a href="login.php">Connexion</a>
</div>
<div class="clean"></div>
</div>
<?php
}
if(isset($_SESSION['username']))
{
?>
<a href="new_topic.php?parent=<?php echo $id; ?>" class="button">Nouveau Sujet</a>
<?php
}
$dn2 = mysql_query('select t.id, t.title, t.authorid, u.username as author, count(r.id) as replies from topics as t left join topics as r on r.parent="'.$id.'" and r.id=t.id and r.id2!=1 left join users as u on u.id=t.authorid where t.parent="'.$id.'" and t.id2=1 group by t.id order by t.timestamp2 desc');
if(mysql_num_rows($dn2)>0)
{
?>
<table class="topics_table" name="topics">
<tr>
<th class="forum_tops">Sujet</th>
<th class="forum_auth">Auteur</th>
<th class="forum_nrep">Réponses</th>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
<th class="forum_act">Action</th>
<?php
}
?>
</tr>
<?php
while($dnn2 = mysql_fetch_array($dn2))
{
?>
<tr>
<td class="forum_tops"><a href="read_topic.php?id=<?php echo $dnn2['id']; ?>"><?php echo htmlentities($dnn2['title'], ENT_QUOTES, 'UTF-8'); ?></a></td>
<td><a href="profile.php?id=<?php echo $dnn2['authorid']; ?>"><?php echo htmlentities($dnn2['author'], ENT_QUOTES, 'UTF-8'); ?></a></td>
<td><?php echo $dnn2['replies']; ?></td>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
<td><a href="delete_topic.php?id=<?php echo $dnn2['id']; ?>"><img src="<?php echo $design; ?>/images/delete.png" alt="Delete" /></a></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
<?php
}
else
{
?>
<div class="message">Cette catégorie ne contient aucun sujet.</div>
<?php
}
if(isset($_SESSION['username']))
{
?>
<a href="new_topic.php?parent=<?php echo $id; ?>" class="button">Nouveau Sujet</a>
<?php
}
else
{
?>
<div class="box_login">
<form action="login.php" method="post">
<label for="username">Nom d'utilisateur</label><input type="text" name="username" id="username" /><br />
<label for="password">Mot de passe</label><input type="password" name="password" id="password" /><br />
<label for="memorize">Se souvenir</label><input type="checkbox" name="memorize" id="memorize" value="yes" />
<div class="center">
<input type="submit" value="Login" /> <input type="button" onclick="javascript:document.location='signup.php';" value="S'inscrire" />
</div>
</form>
</div>
<?php
}
?>
</body>
</html>
<?php
}
else
{
echo '<h2>La catégorie que vous désirez visiter n\'existe pas.</h2>';
}
}
else
{
echo '<h2>L\'identifiant de la catégorie que vous désirez visiter n\'est pas défini.</h2>';
}
?>
<?php
include 'footer.php';
?>
J'ai créer un forum ou j'ai mis plusieurs catégorie et dans chaque catégorie il y a les sujets que l'utilisateur écrit mais mon problème et que si il y a plusieurs sujets dans une catégorie par exemple 100 je veux pas qu'il soient tous dans une pages , c'est pour ça que je veut créer un système de pagination pour mon forum , merci de m'aider
Voila ma la table topics de ma base de donné:
CREATE TABLE 'topics' (
'parent' smallint(6) NOT NULL,
'id' int(11) NOT NULL,
'id2' int(11) NOT NULL,
'title' varchar(256) NOT NULL,
'message' longtext NOT NULL,
'authorid' int(11) NOT NULL,
'timestamp' int(11) NOT NULL,
'timestamp2' int(11) NOT NULL,
PRIMARY KEY ('id','id2')
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
----------------------------------------------------------------------------------
Voila mon code
La page list_topics.php :
<?php
//Cette page permet d'afficher la liste des sujets d'une categorie de forum
include('config.php');
if(isset($_GET['parent']))
{
$id = intval($_GET['parent']);
$dn1 = mysql_fetch_array(mysql_query('select count(c.id) as nb1, c.name,count(t.id) as topics from categories as c left join topics as t on t.parent="'.$id.'" where c.id="'.$id.'" group by c.id'));
if($dn1['nb1']>0)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
<title><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?> - Forum</title>
</head>
<body>
<header>
<?php
include 'header.php';
?>
</header>
<?php
if(isset($_SESSION['username']))
{
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
$nb_new_pm = $nb_new_pm['nb_new_pm'];
?>
<div class="box">
<div class="box_left">
<a href="<?php echo $url_home; ?>">Index du Forum</a> > <a href="list_topics.php?parent=<?php echo $id; ?>"><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>
</div>
<div class="box_right">
<a href="list_pm.php">Vos messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Déconnexion</a>)
</div>
<div class="clean"></div>
</div>
<?php
}
else
{
?>
<div class="box">
<div class="box_left">
<a href="<?php echo $url_home; ?>">Index du Forum</a> > <a href="list_topics.php?parent=<?php echo $id; ?>"><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>
</div>
<div class="box_right">
<a href="signup.php">Inscription</a> - <a href="login.php">Connexion</a>
</div>
<div class="clean"></div>
</div>
<?php
}
if(isset($_SESSION['username']))
{
?>
<a href="new_topic.php?parent=<?php echo $id; ?>" class="button">Nouveau Sujet</a>
<?php
}
$dn2 = mysql_query('select t.id, t.title, t.authorid, u.username as author, count(r.id) as replies from topics as t left join topics as r on r.parent="'.$id.'" and r.id=t.id and r.id2!=1 left join users as u on u.id=t.authorid where t.parent="'.$id.'" and t.id2=1 group by t.id order by t.timestamp2 desc');
if(mysql_num_rows($dn2)>0)
{
?>
<table class="topics_table" name="topics">
<tr>
<th class="forum_tops">Sujet</th>
<th class="forum_auth">Auteur</th>
<th class="forum_nrep">Réponses</th>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
<th class="forum_act">Action</th>
<?php
}
?>
</tr>
<?php
while($dnn2 = mysql_fetch_array($dn2))
{
?>
<tr>
<td class="forum_tops"><a href="read_topic.php?id=<?php echo $dnn2['id']; ?>"><?php echo htmlentities($dnn2['title'], ENT_QUOTES, 'UTF-8'); ?></a></td>
<td><a href="profile.php?id=<?php echo $dnn2['authorid']; ?>"><?php echo htmlentities($dnn2['author'], ENT_QUOTES, 'UTF-8'); ?></a></td>
<td><?php echo $dnn2['replies']; ?></td>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
<td><a href="delete_topic.php?id=<?php echo $dnn2['id']; ?>"><img src="<?php echo $design; ?>/images/delete.png" alt="Delete" /></a></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
<?php
}
else
{
?>
<div class="message">Cette catégorie ne contient aucun sujet.</div>
<?php
}
if(isset($_SESSION['username']))
{
?>
<a href="new_topic.php?parent=<?php echo $id; ?>" class="button">Nouveau Sujet</a>
<?php
}
else
{
?>
<div class="box_login">
<form action="login.php" method="post">
<label for="username">Nom d'utilisateur</label><input type="text" name="username" id="username" /><br />
<label for="password">Mot de passe</label><input type="password" name="password" id="password" /><br />
<label for="memorize">Se souvenir</label><input type="checkbox" name="memorize" id="memorize" value="yes" />
<div class="center">
<input type="submit" value="Login" /> <input type="button" onclick="javascript:document.location='signup.php';" value="S'inscrire" />
</div>
</form>
</div>
<?php
}
?>
</body>
</html>
<?php
}
else
{
echo '<h2>La catégorie que vous désirez visiter n\'existe pas.</h2>';
}
}
else
{
echo '<h2>L\'identifiant de la catégorie que vous désirez visiter n\'est pas défini.</h2>';
}
?>
<?php
include 'footer.php';
?>
1 réponse
Bonjour,
une pagination s'effectue généralement de la manière suivante :
Envoie ton code si tu à besoin de plus d'aide.
Cordialement.
une pagination s'effectue généralement de la manière suivante :
<?php require_once("taconnexionàtabasededonné.inc.php"); try { $retour=$bdd->prepare('SELECT COUNT(*) AS nbimages FROM TaTable WHERE categorie="divers"'); $retour->execute(); $imageparpage=12; $reqtable=$retour->fetch(PDO::FETCH_ASSOC); $totaldesimages=$reqtable['nbimages']; $nombredepage=ceil($totaldesimages/$imageparpage); echo '<span id=miseenformecss>'; echo '<span id="miseenformecss2">'.'Page : '.'</span>'; for ($i=1;$i<= $nombredepage;$i++) { echo '<span id="miseenformecss3"><a href="divers.php?page='.$i.'">'.$i.'</a></span>'; } if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page']>0 && $_GET['page']<= $nombredepage) { $page=intval($_GET['page']); } else { $page=1; } $premiereimageafficher=$page*$imageparpage-$imageparpage; echo '</span>'; $reponse=$bdd->prepare('SELECT id,categorie,image,blabla,etcequetuveut FROM TaTable WHERE categorie= :category ORDER BY id DESC LIMIT :offset, :nbimages'); $reponse->bindValue(':category', 'divers'); $reponse->bindParam(':nbimages', $imageparpage,\PDO::PARAM_INT); $reponse->bindParam(':offset', $premiereimageafficher,\PDO::PARAM_INT); $reponse->execute(); ?> <?php while ($TaTable=$reponse->fetch()) { ?> <div class="cat1"> <?php echo '<span class="classtext1v">'.htmlspecialchars($TaTable['categorie']).'</span>'; ?> <br /> <?php echo '<span class="classtext2v">'.htmlspecialchars($TaTable['titre']).'</span>'; ?> <br /> <img src="images/<?php echo htmlspecialchars($TaTable['image']);?>" width="200" height="250" /></a> </div> <?php } $reponse->closeCursor(); } catch (Exception $e) { echo 'Erreur : ', $e->getMessage(); } ?>
Envoie ton code si tu à besoin de plus d'aide.
Cordialement.
younesase
Messages postés
80
Date d'inscription
Statut
Membre
Dernière intervention
4
merci je vais essayer :) :) :)
reverb94
Messages postés
106
Date d'inscription
Statut
Membre
Dernière intervention
1
Si ton problème est résolu, n'oublie pas de mettre le sujet "résolu" :).