Code php de pagination!!! l'affichage du nbre
mreiwa
Messages postés
109
Statut
Membre
-
mreiwa Messages postés 109 Statut Membre -
mreiwa Messages postés 109 Statut Membre -
Bjr :)
j'applique un code de pagination dan mon fichiers php ,et lorsque j'exécute mon code l'affichage est correcte et pas d'erreur ;mais lorsque je clique sur la page suivant le contenu du la page ne change pas il reste toijours stable malgré jai dans la BD plus que 200 enregistrement.
et voila mon code:
//le code qui me permet d'afficher le contenu du la BD dans un table et il fonctionne correctement:
<?php
@include("connection.php");
$rep=mysql_query("select * ,DATE_FORMAT(date_created,'%d-%m-%Y') as dateFormatee FROM ads ORDER BY date_created DESC limit 0,10");
$dataa=mysql_fetch_assoc($rep);
while($data=mysql_fetch_array($rep))
{
?>
<tr>
<td ><?php echo $data['id']; ?></td>
<td ><?php echo $data['name']; ?></td>
<td ><?php echo $data['ad_headline']; ?></td>
<td ><?php echo $data['ad_text']; ?></td>
<td ><?php echo $data['dateFormatee'];?></td>
<td width="25%"><a href="supprimer_annonce.php?id=<?php echo $data['id']; ?>" onclick="confirme()" > supprimer</a> </td>
</tr>
<?php }
mysql_close();
?>
//voila code de pagination:
<?php
@include("connection.php");
if (!(isset($pagenum)))
{
$pagenum = 1;
}
$data = mysql_query("SELECT * FROM ads") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 10;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM ads $max") or die(mysql_error());
echo "<p>";
echo " --Page $pagenum of $last-- <p>";
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$pr... <-Previous</a> ";
}
echo " ---- ";
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$ne... -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$la... ->></a> ";
}
?>
aidez moi svp et merci d'avonce :)
j'applique un code de pagination dan mon fichiers php ,et lorsque j'exécute mon code l'affichage est correcte et pas d'erreur ;mais lorsque je clique sur la page suivant le contenu du la page ne change pas il reste toijours stable malgré jai dans la BD plus que 200 enregistrement.
et voila mon code:
//le code qui me permet d'afficher le contenu du la BD dans un table et il fonctionne correctement:
<?php
@include("connection.php");
$rep=mysql_query("select * ,DATE_FORMAT(date_created,'%d-%m-%Y') as dateFormatee FROM ads ORDER BY date_created DESC limit 0,10");
$dataa=mysql_fetch_assoc($rep);
while($data=mysql_fetch_array($rep))
{
?>
<tr>
<td ><?php echo $data['id']; ?></td>
<td ><?php echo $data['name']; ?></td>
<td ><?php echo $data['ad_headline']; ?></td>
<td ><?php echo $data['ad_text']; ?></td>
<td ><?php echo $data['dateFormatee'];?></td>
<td width="25%"><a href="supprimer_annonce.php?id=<?php echo $data['id']; ?>" onclick="confirme()" > supprimer</a> </td>
</tr>
<?php }
mysql_close();
?>
//voila code de pagination:
<?php
@include("connection.php");
if (!(isset($pagenum)))
{
$pagenum = 1;
}
$data = mysql_query("SELECT * FROM ads") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 10;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM ads $max") or die(mysql_error());
echo "<p>";
echo " --Page $pagenum of $last-- <p>";
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$pr... <-Previous</a> ";
}
echo " ---- ";
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$ne... -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$la... ->></a> ";
}
?>
aidez moi svp et merci d'avonce :)
A voir également:
- Code php de pagination!!! l'affichage du nbre
- Code ascii - Guide
- Code de déverrouillage oublié - Guide
- Code puk bloqué - Guide
- Code activation windows 10 - Guide
- Affichage double ecran - Guide
5 réponses
/as tu bien mis en commentaires /* */ la partie que je t'avais précisée
rajoutes un echo pour voir si tu recois bien le numero de page attendu:
rajoutes un echo pour voir si tu recois bien le numero de page attendu:
<?php
@include("connection.php");
//tu ne recuperes pas le numero de page passe par l'url lors du click sur le numéro de pagination
//car si dans ton php.ini Regisiter_global est à off il faut le recuperer par $_GET
if(isset($_GET['pagenum'])){
$pagenum = $_GET['pagenum'];
}else{
$pagenum = 1;
}
echo "numero de page recu: ".$pagenum;
$data = mysql_query("SELECT * FROM ads") or die(mysql_error());
$rows = mysql_num_rows($data);
............
mreiwa
Messages postés
109
Statut
Membre
3
lorsque j'ajoute echo et je clique sur next le num du la page change mais le contenu du la table est stable je ne sais pas c quoi la probléme malgré j'ai dans la table "ads" plus que 400 enregistrement !!!
//voila code de pagination:
<?php
@include("connection.php");
//tu ne recuperes pas le numero de page passe par l'url lors du click sur le numéro de pagination
//car si dans ton php.ini Regisiter_global est à off il faut le recuperer par $_GET
if(isset($_GET['pagenum'])){
$pagenum = $_GET['pagenum'];
}else{
$pagenum = 1;
}
/*
if (!(isset($pagenum)))
{
$pagenum = 1;
}
*/
$data = mysql_query("SELECT * FROM ads") or die(mysql_error());
$rows = mysql_num_rows($data);
...................
modifies ton code ainsi:
$max = ' LIMIT '.($pagenum - 1) * $page_rows .',' .$page_rows; //mets un espace avant LIMIT /*et un echo pour voir si le cacul est bon au premier coup tu dois avoir LIMIT 0,10 au deuxieme 10,10 au 3ieme 20,10 etc... */ echo 'numero de page= '.$pagenum.' valeur de $max: '.$max;
j'applique votre code et voila la résultat"numero de page= 5 valeur de $max: LIMIT 40,10"
c_à_d il fonctionne bien mais comme l'habitude le contenu du la table ne varie pas et je ne sais c koi la probléme !!!
//voila mon code du la table:
<table width="95%" height="122" cellspacing="0" >
<tr>
<th width="10%" >ID</th>
<th width="14%" >Name</th>
<th width="16%" >Titre d annonce</th>
<th width="25%" >Text </th>
<th width="10%">Date</th>
<th></th>
</tr>
<?php
@include("connection.php");
$rep=mysql_query("select * ,DATE_FORMAT(date_created,'%d-%m-%Y') as dateFormatee FROM ads ORDER BY date_created DESC limit 0,10");
$dataa=mysql_fetch_assoc($rep);
while($data=mysql_fetch_array($rep))
{
?>
<tr>
<td ><?php echo $data['id']; ?></td>
<td ><?php echo $data['name']; ?></td>
<td ><?php echo $data['ad_headline']; ?></td>
<td ><?php echo $data['ad_text']; ?></td>
<td ><?php echo $data['dateFormatee'];?></td>
<td width="25%"><a href="supprimer_annonce.php?id=<?php echo $data['id']; ?>" onclick="confirme()" > supprimer</a> </td>
</tr>
<?php }
mysql_close();
?>
</table>
tous fonctionne correctement ,l'adresse url varie et la pagination bien sur; sauf :lors de la clique sur next le contenu du table ne varie pas et je ne sais pas ou la probléme exactement!!
c_à_d il fonctionne bien mais comme l'habitude le contenu du la table ne varie pas et je ne sais c koi la probléme !!!
//voila mon code du la table:
<table width="95%" height="122" cellspacing="0" >
<tr>
<th width="10%" >ID</th>
<th width="14%" >Name</th>
<th width="16%" >Titre d annonce</th>
<th width="25%" >Text </th>
<th width="10%">Date</th>
<th></th>
</tr>
<?php
@include("connection.php");
$rep=mysql_query("select * ,DATE_FORMAT(date_created,'%d-%m-%Y') as dateFormatee FROM ads ORDER BY date_created DESC limit 0,10");
$dataa=mysql_fetch_assoc($rep);
while($data=mysql_fetch_array($rep))
{
?>
<tr>
<td ><?php echo $data['id']; ?></td>
<td ><?php echo $data['name']; ?></td>
<td ><?php echo $data['ad_headline']; ?></td>
<td ><?php echo $data['ad_text']; ?></td>
<td ><?php echo $data['dateFormatee'];?></td>
<td width="25%"><a href="supprimer_annonce.php?id=<?php echo $data['id']; ?>" onclick="confirme()" > supprimer</a> </td>
</tr>
<?php }
mysql_close();
?>
</table>
tous fonctionne correctement ,l'adresse url varie et la pagination bien sur; sauf :lors de la clique sur next le contenu du table ne varie pas et je ne sais pas ou la probléme exactement!!
essayes avec ce code:(voir commentaires)
<?php
@include("connection.php");
if(isset($_GET['pagenum'])){
$pagenum = $_GET['pagenum'];
}else{
$pagenum = 1;
}
$data = mysql_query("SELECT * FROM ads") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 10;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$result = mysql_query("SELECT * FROM ads $max") or die(mysql_error());
//c'est bien de faire une requette mais il faut afficher le résultat, hors toi ce que tu affichait c'est le résultat issu d'une requette qui avait une LIMIT 0,10 fixe !!!
//alors c'est la qu'il faut mettre ta table afichage
?>
<table width="95%" height="122" cellspacing="0" >
<tr>
<th width="10%" >ID</th>
<th width="14%" >Name</th>
<th width="16%" >Titre d annonce</th>
<th width="25%" >Text </th>
<th width="10%">Date</th>
<th></th>
</tr>
<?php
while($data=mysql_fetch_array($result))
{
?>
<tr>
<td ><?php echo $data['id']; ?></td>
<td ><?php echo $data['name']; ?></td>
<td ><?php echo $data['ad_headline']; ?></td>
<td ><?php echo $data['ad_text']; ?></td>
<td ><?php echo $data['dateFormatee'];?></td>
<td width="25%"><a href="supprimer_annonce.php?id=<?php echo $data['id']; ?>" onclick="confirme()" > supprimer</a> </td>
</tr>
<?php }
mysql_close();
?>
</table>
<?php
echo "<p>";
echo " --Page $pagenum of $last-- <p>";
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$pr... <-Previous</a> ";
}
echo " ---- ";
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$ne... -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$la... ->></a> ";
}
?>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question