Vous n'êtes pas identifié.
Salut.
J'ai une page de derniers ajouts et j'aimerai la multiplier par 10 tout en gardant 15 images par page.
Voici mon script :
<?php include("inc_appel.php"); ?>
<!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 profile="http://gmpg.org/xfn/11">
<title> | Les derniers ajouts</title>
<!-- DEBUT SCRIPT ET META -->
<?php include("inc_script.php"); ?>
<!-- FIN SCRIPT ET META -->
</head>
<body id="top">
<div id="wrapper">
<!-- DEBUT HEADER -->
<?php include("inc_header.php"); ?>
<!-- FIN HEADER -->
<div id="main">
<div id="main-inner">
<div class="contentwide">
<div class="content">
<div class="boxpost">
<div class="post" id="post-53">
<div class="entry">
<table style="margin:auto">
<tr>
<td style="text-align:center; border:1px solid black; padding:5px" onmouseover="this.style.backgroundColor='#ff66cc';" onmouseout="this.style.backgroundColor='';"><a style="text-decoration:none; color:black" href="index.php"><span style="font-size:12px">NOUVEAUTES</span></a></td>
<td style="text-align:center; border:1px solid black; padding:5px; background-color:#ff66cc"><a style ="text-decoration:none; color:black" href=""><span style="font-size:12px"><b>DERNIERS AJOUTS</b></span></a></td>
<td style="text-align:center; border:1px solid black; padding:5px" onmouseover="this.style.backgroundColor='#ff66cc';" onmouseout="this.style.backgroundColor='';"><a style ="text-decoration:none; color:black" href="films-au-hasard.html"><span style="font-size:12px">AU HASARD</span></a></td>
</tr>
</table> <br />
<?php
$reponse = mysql_query("SELECT * FROM films WHERE url_image!='' ORDER BY date DESC LIMIT 0,15") or die(mysql_error());
while ($donnees = mysql_fetch_array($reponse))
{ ?>
<a href="<?php echo $donnees['id']; ?>-<?php echo $donnees['url']; ?>.html" style="text-decoration:none"><img title="<?php echo stripslashes($donnees['titre']); ?>" src="<?php echo $donnees['url_image']; ?>" style="width:200px; height:267px; border:4px solid #efefef" onmouseover="this.style.borderColor = '#ffd600'" onmouseout="this.style.borderColor = '#efefef'"/></a>
<?php } ?>
<br />
<div style="clear:both;"></div>
</div> <!-- end entry -->
</div> <!-- end post -->
</div> <!-- end boxpost -->
<div style="clear:both;"></div>
</div> <!-- end content -->Je n'y arrive pas... peux-tu m'aider.
Merci d'avance....
Amitiés
Hors ligne

Salut stero11,
J'ai un peut de mal avec ton explication... tu veux multiplier par 10 ta liste tout en gardant 15 images...c'est à dire?
ça doit avoir quelle rendu exactement puisque que tu fais des liens sur les images?
Si tu appels 150 entrée mais que tu veux afficher que 15 images, tu fais quoi des 135 autres entrées?
Il y a vraiment un truc que je n'ai pas saisie 
Hors ligne
c'est vrai des fois je ne suis pas super explicite....
je veux tout simplement 10 pages avec 15 images
soit page 1 : image 1-15
soit page 2 : image 16-30
etc
J'espère que je suis plus clair
Dernière modification par c00lman (22-12-2011 08:45:51)
Hors ligne
ça s'appelle une pagination.
Histoire d'être bien sûre, voici un exemple http://creer.mon.site.free.fr/cms-free-fr/ sauf que la pour l'exemple j'ai limité à un affichage par page...c'est bien ça que tu veux obtenir?
Hors ligne
Voila c'est bien ça
Hors ligne
Dans un fichier nommé "pagination.php" :
<?php
function pagination($current_page, $nb_pages, $param = FALSE, $link='?page=%d', $around=6, $firstlast=1) {
$pagination = '';
$link = preg_replace('`%([^d])`', '%%$1', $link);
if (!preg_match('`(?<!%)%d`', $link))
$link .= '%d';
if ($nb_pages > 1) {
// Lien précédent
if ($current_page > 1)
if(!isset($param))
$pagination .= '<a class="prevnext" href="'.sprintf($link, $current_page-1).'" title="Page précédente">« Précédent</a>';
else
$pagination .= '<a class="prevnext" href="'.sprintf($link, $current_page-1). $param .'" title="Page précédente">« Précédent</a>';
else
$pagination .= '<span class="prevnext disabled">« Précédent</span>';
// Lien(s) début
for ( $i=1 ; $i<=$firstlast ; $i++ ) {
$pagination .= ' ';
if(!isset($param))
$pagination .= ($current_page==$i) ? '<span class="current">'.$i.'</span>' : '<a title="Page '.$i.'" href="'.sprintf($link, $i).'">'.$i.'</a>';
else
$pagination .= ($current_page==$i) ? '<span class="current">'.$i.'</span>' : '<a title="Page '.$i.'" href="'.sprintf($link, $i). $param .'">'.$i.'</a>';
}
// ... après pages début ?
if (($current_page-$around) > $firstlast+1)
$pagination .= ' …';
// On boucle autour de la page courante
$start = ($current_page-$around)>$firstlast ? $current_page-$around : $firstlast+1;
$end = ($current_page+$around)<=($nb_pages-$firstlast) ? $current_page+$around : $nb_pages-$firstlast;
for ( $i=$start ; $i<=$end ; $i++ ) {
$pagination .= ' ';
if ( $i==$current_page )
$pagination .= '<span class="current">'.$i.'</span>';
else
if(!isset($param))
$pagination .= '<a title="Page '.$i.'" href="'.sprintf($link, $i).'">'.$i.'</a>';
else
$pagination .= '<a title="Page '.$i.'" href="'.sprintf($link, $i). $param .'">'.$i.'</a>';
}
// ... avant page nb_pages ?
if ( ($current_page+$around) < $nb_pages-$firstlast )
$pagination .= ' …';
// Lien(s) fin
$start = $nb_pages-$firstlast+1;
if($start <= $firstlast)
$start = $firstlast+1;
for ( $i=$start ; $i<=$nb_pages ; $i++ ) {
$pagination .= ' ';
if(!isset($param))
$pagination .= ($current_page==$i) ? '<span class="current">'.$i.'</span>' : '<a title="Page '.$i.'" href="'.sprintf($link, $i).'">'.$i.'</a>';
else
$pagination .= ($current_page==$i) ? '<span class="current">'.$i.'</span>' : '<a title="Page '.$i.'" href="'.sprintf($link, $i). $param .'">'.$i.'</a>';
}
// Lien suivant
if ($current_page < $nb_pages) {
if(!isset($param))
$pagination .= ' <a class="prevnext" href="'.sprintf($link, ($current_page+1)).'" title="Page suivante">Suivant »</a>';
else
$pagination .= ' <a class="prevnext" href="'.sprintf($link, ($current_page+1)).$param.'" title="Page suivante">Suivant »</a>';
} else {
$pagination .= ' <span class="prevnext disabled">Suivant »</span>';
}
}
return $pagination;
}
//on affiche la pagination
echo '<p class="pagination">' . pagination($pageActuelle, $nombreDePages) . '</p>';
?>Dans ton fichier actuel :
<?php
//--------------Début requête de pagination----------------------
$retour_total=mysql_query("SELECT COUNT(*) AS total FROM films WHERE url_image!='' ORDER BY date DESC LIMIT 0,150") or die(mysql_error());
$donnees_total=mysql_fetch_assoc($retour_total);
$total=$donnees_total['total'];
$nombreDePages=ceil($total/$messagesParPage);
if(isset($_GET['page']))
{
$pageActuelle=intval($_GET['page']);
if($pageActuelle>$nombreDePages)
{
$pageActuelle=$nombreDePages;
}
}
else
{
$pageActuelle=1;
}
$premiereEntree=($pageActuelle-1)*$messagesParPage;
//---------------Fin de requête pagination--------------------------
//Requête
$reponse = mysql_query("SELECT * FROM films WHERE url_image!='' ORDER BY date DESC LIMIT ".$premiereEntree." , ".$messagesParPage." ") or die(mysql_error());
while ($donnees = mysql_fetch_array($reponse))
{
?>
<a href="<?php echo $donnees['id']; ?>-<?php echo $donnees['url']; ?>.html" style="text-decoration:none"><img title="<?php echo stripslashes($donnees['titre']); ?>" src="<?php echo $donnees['url_image']; ?>" style="width:200px; height:267px; border:4px solid #efefef" onmouseover="this.style.borderColor = '#ffd600'" onmouseout="this.style.borderColor = '#efefef'"/></a>
<?php
}
//On inclue le système de Pagination
include('pagination.php');
?>Code non testé...
Hors ligne
j'ai une petite erreur :
Warning: Division by zero in /home/xxxxxxxx/public_html/page2.php on line 87
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mais je ne sais pas si j'ai intégré ton code au bon endroit
donc je te copie le code de la page en entier modifiée :
<?php include("inc_appel.php"); ?>
<!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 profile="http://gmpg.org/xfn/11">
<title> | Les derniers ajouts</title>
<!-- DEBUT SCRIPT ET META -->
<?php include("inc_script.php"); ?>
<!-- FIN SCRIPT ET META -->
</head>
<body id="top">
<div id="wrapper">
<!-- DEBUT HEADER -->
<?php include("inc_header.php"); ?>
<!-- FIN HEADER -->
<div id="main">
<div id="main-inner">
<div class="contentwide">
<div class="content">
<div class="boxpost">
<div class="post" id="post-53">
<div class="entry">
<table style="margin:auto">
<tr>
<td style="text-align:center; border:1px solid black; padding:5px" onmouseover="this.style.backgroundColor='#ff66cc';" onmouseout="this.style.backgroundColor='';"><a style="text-decoration:none; color:black" href="index.php"><span style="font-size:12px">NOUVEAUTES</span></a></td>
<td style="text-align:center; border:1px solid black; padding:5px; background-color:#ff66cc"><a style ="text-decoration:none; color:black" href=""><span style="font-size:12px"><b>DERNIERS AJOUTS</b></span></a></td>
<td style="text-align:center; border:1px solid black; padding:5px" onmouseover="this.style.backgroundColor='#ff66cc';" onmouseout="this.style.backgroundColor='';"><a style ="text-decoration:none; color:black" href="films-au-hasard.html"><span style="font-size:12px">AU HASARD</span></a></td>
</tr>
</table> <br />
<?php
//--------------Début requête de pagination----------------------
$retour_total=mysql_query("SELECT COUNT(*) AS total FROM films WHERE url_image!='' ORDER BY date DESC LIMIT 0,150") or die(mysql_error());
$donnees_total=mysql_fetch_assoc($retour_total);
$total=$donnees_total['total'];
$nombreDePages=ceil($total/$messagesParPage);
if(isset($_GET['page']))
{
$pageActuelle=intval($_GET['page']);
if($pageActuelle>$nombreDePages)
{
$pageActuelle=$nombreDePages;
}
}
else
{
$pageActuelle=1;
}
$premiereEntree=($pageActuelle-1)*$messagesParPage;
//---------------Fin de requête pagination--------------------------
//Requête
$reponse = mysql_query("SELECT * FROM films WHERE url_image!='' ORDER BY date DESC LIMIT ".$premiereEntree." , ".$messagesParPage." ") or die(mysql_error());
while ($donnees = mysql_fetch_array($reponse))
{
?>
<a href="<?php echo $donnees['id']; ?>-<?php echo $donnees['url']; ?>.html" style="text-decoration:none"><img title="<?php echo stripslashes($donnees['titre']); ?>" src="<?php echo $donnees['url_image']; ?>" style="width:200px; height:267px; border:4px solid #efefef" onmouseover="this.style.borderColor = '#ffd600'" onmouseout="this.style.borderColor = '#efefef'"/></a>
<?php
}
//On inclue le système de Pagination
include('pagination.php');
?>
<br />
<div style="clear:both;"></div>
</div> <!-- end entry -->
</div> <!-- end post -->
</div> <!-- end boxpost -->
<div style="clear:both;"></div>
</div> <!-- end content -->
<!-- DEBUT MENU DE DROITE-->
<?php include("inc_menu_droite.php"); ?>
<!-- FIN MENU DE DROITE-->
</div> <!-- end contentwide -->
</div><!-- end main-inner -->
</div><!-- main -->
<!-- DEBUT FOOTER -->
<?php include("inc_footer.php"); ?>
<!-- FIN FOOTER -->
</div><!-- end wrapper -->
</body>
</html>Hors ligne
Dans la première requête, vire le zéro :
ORDER BY date DESC LIMIT 150
Hors ligne
toujour le message suivant :
Warning: Division by zero in /home/xxxxxx/public_html/page2.php on line 87
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Hors ligne
Merdouille alors
!
Vire carrément la partie suivante de la première requête :
ORDER BY date DESC LIMIT 0,150
Hors ligne
salut...
Je ne comprend pas ce que tu veux me faire faire.
voici donc la requete :
$retour_total=mysql_query("SELECT COUNT(*) AS total FROM films WHERE url_image!='' ORDER BY date DESC LIMIT 0,150") or die(mysql_error());Hors ligne
$retour_total=mysql_query("SELECT COUNT(*) AS total FROM films WHERE url_image!=''") or die(mysql_error());Hors ligne
ben ça change rien... tjrs la meme erreur
Hors ligne
Arffff, j'ai oublié de définir la variable $messagesParPage
...
<?php
$messagesParPage = 15;
//--------------Début requête de pagination----------------------
$retour_total=mysql_query("SELECT COUNT(*) AS total FROM films WHERE url_image!=''") or die(mysql_error());
$donnees_total=mysql_fetch_assoc($retour_total);
$total=$donnees_total['total'];
$nombreDePages=ceil($total/$messagesParPage);
if(isset($_GET['page']))
{
$pageActuelle=intval($_GET['page']);
if($pageActuelle>$nombreDePages)
{
$pageActuelle=$nombreDePages;
}
}
else
{
$pageActuelle=1;
}
$premiereEntree=($pageActuelle-1)*$messagesParPage;
//---------------Fin de requête pagination--------------------------
//Requête
$reponse = mysql_query("SELECT * FROM films WHERE url_image!='' ORDER BY date DESC LIMIT ".$premiereEntree." , ".$messagesParPage." ") or die(mysql_error());
while ($donnees = mysql_fetch_array($reponse))
{
?>
<a href="<?php echo $donnees['id']; ?>-<?php echo $donnees['url']; ?>.html" style="text-decoration:none"><img title="<?php echo stripslashes($donnees['titre']); ?>" src="<?php echo $donnees['url_image']; ?>" style="width:200px; height:267px; border:4px solid #efefef" onmouseover="this.style.borderColor = '#ffd600'" onmouseout="this.style.borderColor = '#efefef'"/></a>
<?php
}
//On inclue le système de Pagination
include('pagination.php');
?>Edit : J'ai supprimé " ORDER BY date" dans la première requête puisqu'elle se trouve dans la seconde.
Hors ligne
oki ça marche....
j'essaye de limité au 10 pages comme prévu et la j'ai la totalité des pages qui arrive.... logiquement il ne devrait y avoir que 150 images en tout et la il fait tout apparaitre....
j'ai testé
$retour_total=mysql_query("SELECT COUNT(*) AS total FROM films WHERE url_image!='' ORDER BY date DESC LIMIT 0,150") or die(mysql_error());et
$retour_total=mysql_query("SELECT COUNT(*) AS total FROM films WHERE url_image!='' ORDER BY date DESC LIMIT 150") or die(mysql_error());et la totalité sort tjrs
Hors ligne
Bha la je sèche...j'aurais fait exactement la même chose!
Après un teste, il s'avère que la clause LIMIT na aucun impact sur un COUNT.
Essaye ceci :
Vire la partie :
$retour_total=mysql_query("SELECT COUNT(*) AS total FROM films WHERE url_image!=''") or die(mysql_error());
$donnees_total=mysql_fetch_assoc($retour_total);
$total=$donnees_total['total'];et remplace par :
$total=150;
Comme "$total" renvoie le nombre total de ligne de la table, ça devrait fonctionner.
Hors ligne
impec la ça marche.... merci bcp et joyeu noel
Hors ligne
Hors ligne
Propulsé par PunBB
© Copyright 2007
Forum créer un site