function num ($start, $max, $nombre)
{
// ON CREE LES VARIABLES
$start = $_GET["start"];
// SI START EXISTE PAS
if(!$start)
{
$start = 0;
}
// NOMBRE DE MESSAGES A AFFICHER PAR PAGE
$nombre = 10;
// NOMBRE DE PAGE
$page_tot = ceil($max / $nombre);
// NUMERO DE LA PAGE ACTIVE
$page_nombre_actuel = ($start / $nombre) + 1;
// NOMBRE DE LA PAGE PRECEDANTE
$page_nombre_precedant = $page_nombre_actuel - 1;
// NOMBRE DE LA PAGE SUIVANTE
$page_nombre_suivante = $page_nombre_actuel + 1;
// NOMBRE DE LA PAGE SUIVANTE DE LA PAGE SUIVANTE
$page_nombre_suivante_suivante = $page_nombre_actuel + 2;
// LIEN PRECEDANT
// SI IL Y A UNE PAGE PRECEDANTE, LIEN SINON PAS
if($start >= $nombre)
{
echo"» <a href=\"index.php?page=id/id&start=".($start - $nombre)."\">Précédent</a>";
}
else
{
echo"» Précédent";
}
// SEPARATION
echo" | ";
// SI PRECEDANT EST PAS EGAL A 1
if($page_nombre_precedant != "1")
{
// SI SUIVANT EST PAS EGAL A 2
if($page_nombre_suivante != "2")
{
// SI PRECEDANT EST EGAL A 2
if($page_nombre_precedant == "2")
{
echo"<a href=\"index.php?page=id/id&start=0\">1</a> ";
}
else
{
echo"<a href=\"index.php?page=id/id&start=0\">1</a> ... ";
}
}
}
// SI PRECEDENT EXISTE
if($start >= $nombre)
{
echo"<a href=\"index.php?page=id/id&start=".(($page_nombre_precedant - 1) * $nombre)."\">".$page_nombre_precedant."</a> ";
}
// PAGE ACTUELLE
if($page_tot == 1)
{
echo"".$page_nombre_actuel."";
}
else
{
echo"".$page_nombre_actuel." ";
}
// SI SUIVANT EXISTE
if($max > $start + $nombre)
{
echo"<a href=\"index.php?page=id/id&start=".(($page_nombre_suivante - 1) * $nombre)."\">".$page_nombre_suivante."</a>";
}
// SI PRECEDANT EST PAS EGAL A L'AVANT DERNIERE PAGE
if($page_nombre_precedant != $page_tot - 1)
{
// SI SUIVANT N'EST PAS LA DERNIERE PAGE
if($page_nombre_suivante != $page_tot)
{
// SI LA PAGE SUIVANT LA SUIVANT N'EST PAS LA DERNIERE PAGE
if($page_nombre_suivante_suivante == $page_tot)
{
echo" <a href=\"index.php?page=id/id&start=".(($page_tot - 1) * $nombre)."\">".$page_tot."</a>";
}
else
{
echo" ... <a href=\"index.php?page=id/id&start=".(($page_tot - 1) * $nombre)."\">".$page_tot."</a>";
}
}
}
// LIEN SUIVANT
// SEPARATION
echo" | ";
// SI IL Y A UNE PAGE SUIVANTE, LIEN SINON PAS
if($max > $start + $nombre)
{
echo"<a href=\"index.php?page=id/id&start=".($start + $nombre)."\">Suivante</a>";
}
else
{
echo"Suivant\n";
}
}
Bon je sais, ça fait un gros code, mais vala quoi! Ce que je cherche à faire c'est changer le start et surtout comment le définir...
plutôt que [code] pour du code PHP.
C'est plus joli comme ça non ?
<?php
class paginateur {
//Mémoire de l'objet
var $page; //liste des pages à afficher
var $sens; //sens de navigation
var $current; //n° page en cours
//Démarre l'objet
function démarrer(){
//Réception des paramètres
$this->page = isset($_GET["page"])?$_GET["page"]:$this->page;
$this->sens = isset($_GET["sens"])?$_GET["sens"]:"";
$this->current = isset($_GET["current"])&&$_GET["current"]<count($this->page)&&$_GET["current"]>=0?$_GET["current"]:0;
//Si un index de page est choisi : afficher diretement la page
if (isset($_GET["page_directe"])&& !empty($_GET["page_directe"])){
$this->current = $_GET["page_directe"]<count($this->page)&&$_GET["page_directe"]>=0?$_GET["page_directe"]:0;
}else
//sinon : un bouton de navigation est choisi : calculer le n° de la page à afficher
switch ($this->sens){
case "|<": $this->current = 0; break;
case "<": $this->current--; break;
case ">": $this->current++; break;
case ">|": $this->current = count($this->page)-1; break;
}
//Affichage de la page ciblée
echo $this->getPage($this->current);
//Affichage du paginateur
echo "<hr>";
if ($this->page!=null)
foreach($this->page as $p=>$x)
echo "<A href='?page_directe=$p'>".($p+1)."</A> <input type=hidden name=page[] value='$p'>";
echo "
<p><form>
<input type=submit name=sens value='|".htmlspecialchars("<")."'>";
if ($this->current >0) echo "<input type=submit name=sens value='".htmlspecialchars("<")."'>";
if ($this->current <count($this->page)-1) echo "<input type=submit name=sens value='".htmlspecialchars(">")."'>";
echo "<input type=submit name=sens value='".htmlspecialchars(">")."|'>
<input type=hidden name=current value='$this->current'>
</form>
";
}
//lecture de la page à afficher
function getPage($page){
//ceci est un exemple de technique d'affichage de contenu pour le test
if (file_exists($this->page[$page])) include ($this->page[$page]); else return "<h1>Erreur: Page non trouvée</h1>";
}
//Alimentation de la memoire des pages
function page_add($fichier_source){
if (file_exists($fichier_source))$this->page[] = $fichier_source;
}
}//fin de la classe
//Test
$paginateur = new paginateur();
//On ajoute les pages à gérer par le paginateur (dans cette version, il n'est pas possible de spécifier un dossier mais un fichier final)
$paginateur->page_add("p1.htm");
$paginateur->page_add("p2.htm");
$paginateur->page_add("p3.htm");
//Activer le paginateur
$paginateur->démarrer();
?>
<?php
// ON CREE LES VARIABLES ABREGEES
$num = $_GET["num"];
$mode = $_GET["mode"];
$gal = $_GET["gal"];
// ON INCLUT LES INFOS SUR LE TITRE ETC.
require_once("pho/inf.php");
// ON OUVRE LE DOSSIER
if($mode == "min" || !isset($mode)) // POUR LES MINIATURES
{
$dir = $chmin;
}
elseif($mode == "voir") // POUR LES TAILLES NORMALES
{
$dir = $chnor;
}
$dossier = opendir($dir);
// ON CREE LE COMPTEUR
$i = 0;
// ON TESTE LES FICHIERS DU DOSSIER
while($img = readdir($dossier))
{
if(eregi(".gif",$img) || eregi(".jpg",$img) || eregi(".png",$img)) // "SCANNING" DES TYPES-IMAGES DANS DOSSIER
{
$a[$i] = $img; // ON PLACE LE NOM DE FICHIER DANS UN TABLEAU (ARRAY)
$i++; // ON INCREMENTE
}
}
// ON CHOPPE LE MAXI D'IMAGES DE LA GALLERIE
$max = $i;
// ON RECUPERE LE NUMERO DE L'IMAGE A AFFICHER EN PREMIER
if(empty($num) || $num > $max - 1)
{
$num = 1;
}
else
{
$num = $num;
}
// POUR LES MINIATURES
if($mode == "min" || !isset($mode))
{
echo"<h1>".$tit." | Miniatures</h1>\n"; // TITRE
// PREMIER BLOC (A GAUCHE)
echo"<div class=\"quart\">\n";
for ($num = 1 ; $num <= $max; $num += 4) // BOUCLE QUI COMMENCE PAR 1
{
echo"<p class=\"centre\"><a href=\"index.php?page=pho/gal&menu=cgau/pho&gal=".$gal."&mode=voir&num=".$num."\"><img src=\"".htmlentities($chmin.$num).".jpg\" alt=\"\" /></a></p>\n";
}
echo"</div>\n";
// DEUXIEME BLOC (MILLIEU A GAUCHE)
echo"<div class=\"quart\">\n";
for ($num = 2 ; $num <= $max; $num += 4) // BOUCLE QUI COMMENCE PAR 2
{
echo"<p class=\"centre\"><a href=\"index.php?page=pho/gal&menu=cgau/pho&gal=".$gal."&mode=voir&num=".$num."\"><img src=\"".htmlentities($chmin.$num).".jpg\" alt=\"\" /></a></p>\n";
}
echo"</div>\n";
// TROISIEME BLOC (MILLIEU A DROITE)
echo"<div class=\"quart\">\n";
for ($num = 3 ; $num <= $max; $num += 4) // BOUCLE QUI COMMENCE PAR 3
{
echo"<p class=\"centre\"><a href=\"index.php?page=pho/gal&menu=cgau/pho&gal=".$gal."&mode=voir&num=".$num."\"><img src=\"".htmlentities($chmin.$num).".jpg\" alt=\"\" /></a></p>\n";
}
echo"</div>\n";
// QUATRIEME BLOC (TOUT A DROITE)
echo"<div class=\"quart\">\n";
for ($num = 4 ; $num <= $max; $num += 4) // BOUCLE QUI COMMENCE PAR 4
{
echo"<p class=\"centre\"><a href=\"index.php?page=pho/gal&menu=cgau/pho&gal=".$gal."&mode=voir&num=".$num."\"><img src=\"".htmlentities($chmin.$num).".jpg\" alt=\"\" /></a></p>\n";
}
echo"</div>\n";
// SEPARATION
echo"<div class=\"espace\"></div>\n";
}
// POUR UNE SEULE IMAGE
elseif($mode == "voir")
{
echo"<h1>".$tit." | Photos ".$num."/".$i."</h1>\n"; // TITRE
// POUR LES PRECEDANTS
if($num <= 1)
{
// PRECEDANT SANS LIEN + RETOUR AUX MINIATURES
echo "<p class=\"centre\">Précédente | <a href=\"index.php?page=pho/gal&menu=cgau/pho&gal=".$gal."&mode=min\">Retour aux miniatures</a> | ";
}
else
{
// PRECEDANT EXISTE + RETOUR AU MINIATURES
$pre = $num - 1;
echo"<p class=\"centre\"><a href=\"index.php?page=pho/gal&menu=cgau/pho&gal=".$gal."&mode=voir&num=".$pre."\">Précédente</a> | <a href=\"index.php?page=pho/gal&menu=cgau/pho&gal=".$gal."&mode=min\">Retour aux miniatures</a> | ";
}
// POUR LES SUIVANTS
if($num >= $max - 1)
{
// SUIVANT SANS LIEN
echo "Suivante</p>\n";
}
else
{
// SUIVANT EXISTE
$sv = $num + 1;
echo "<a href=\"index.php?page=pho/gal&menu=cgau/pho&gal=".$gal."&mode=voir&num=".$sv."\">Suivante</a></p>\n";
}
// L'IMAGE S'AFFICHE
echo"<div class=\"centre\">\n";
echo "<img src=\"".htmlentities($chnor.$num).".jpg\" alt=\"\" />\n";
echo"</div>\n";
}
On début d'ébauche serait la bienvenue comme ça je pourrais l'apprendre, merci en tt les cas!!!
$numeroDeLaPage = xx; // a récupérer dans le request
$nbElementsParPage = 3; // a choisir
$index = $numeroDeLaPage * $nbElementsParPage;
// pour les éléments du tableau $a compris dans l'interval [index, index+3]
for ($i = $index; $i < $index+$nbElementsParPage && $i < count($a) ; $i++) {
echo $a[$i]; // affichage des elements de la page uniquement
...
}
En espérant que ce soit plus clair ainsi
j'ai tres recemment poster sur ce forum une question a ce sujet je t'envoi vers ce poste en esperant qu'il pourra t'aider
http://www.phpfrance.com/forums/viewtop ... highlight=