Afficher un nb défini de produits par page

youplaboum -  
 Utilisateur anonyme -
Bonjour,

j'ai un site ou j'affiche les produits d'une base de donnée
et je voudrais pouvoir en afficher soit 5 ou 10 ou meme 20 par page
comment faire cela et comment créer automatiquement les pages ou
sont les produits suivant : 1-5 6-10 11-15....
comme ca

je c'est que je dois utiliser un compte
$nbProd = mysql_query("select count(*) as nbProd from produits order by Reference");

pour avoir le nombre de produit puis diviser par le nombre de produits a afficher pour avoir le nombre de page
puis utiliser la fonction limit dans mon query pour afficher les produits

merci d'avance de votre aide
Configuration: Windows NT 4.0
Firefox 2.0

4 réponses

  1. Utilisateur anonyme
     
    tu peux t'inspirer de cette fonction :
    pour toi
    $tab =$nbProd
    $limitPas c'est le nombre de res que tu veux afficher
    $limitEC c'est ta position
    $get2 c'est pour paC des info suplémentaire

    va y avoir de l'adaptation mais en gros c'est pour te filer la logique

    bon courage

    function pagination($tab,$limitPas,$limitEC,$get2){

    if ( (stristr($_SERVER['PHP_SELF'], 'control') === FALSE) )
    $chm = '';
    else $chm = '../';

    if(count($tab)>$limitPas){
    $tmp=explode("&",$_SERVER["QUERY_STRING"]);
    $gette=array();
    foreach($tmp as $itm){
    $val=explode("=",$itm);
    array_push($gette,$val);
    }
    //-----Début
    print("<!--pagination-->\n");
    print("<div class='pagination'>\n");
    if($limitEC>=$limitPas*2)

    if ( (stristr($_SERVER['PHP_SELF'], 'control') === FALSE) )
    print("<a href='#' class='pagination' onclick='postData(\"spip.php\",\"limitEC=0&limitPas=".$limitPas.$get2."\",\"\")'><IMG src='".$chm."IMG/grosse_puce_fleche_gauche.gif' width='11' height='8' alt='Debut' /> Début</a>");
    else
    print("<a href='#' class='pagination' onclick='postData(\"index.php\",\"limitEC=0&limitPas=".$limitPas.$get2."\",\"act=financements\")'><IMG src='".$chm."IMG/grosse_puce_fleche_gauche.gif' width='11' height='8' alt='Debut' /> Début</a>");
    //-----Précédent
    if($limitEC>0){
    if($limitEC-$limitPas>0)
    $lim=$limitEC-$limitPas;
    else
    $lim=0;

    if ( (stristr($_SERVER['PHP_SELF'], 'control') === FALSE) )
    print("<a href='#' class='pagination' onclick='postData(\"spip.php\",\"limitEC=".$lim."&limitPas=".$limitPas.$get2."\",\"\")'><IMG src='".$chm."IMG/gauche_seul.gif' width='6' height='8' alt='Précédent' /> Précédent</a>");
    else
    print("<a href='#' class='pagination' onclick='postData(\"index.php\",\"limitEC=".$lim."&limitPas=".$limitPas.$get2."\",\"act=financements\")'><IMG src='".$chm."IMG/gauche_seul.gif' width='6' height='8' alt='Précédent' /> Précédent</a>");
    }
    //-----Les pages

    $max=intval(count($tab)/$limitPas)*$limitPas;
    if($max==count($tab))
    $max-=$limitPas;
    for($j=0;$j<=$max;$j+=$limitPas){
    $lim=$j;
    if($lim>=count($tab))
    $lim-=$limitPas;
    if($j!=$limitEC){

    if ( (stristr($_SERVER['PHP_SELF'], 'control') === FALSE) )
    print("<a href='#' class='pagination' onclick='postData(\"spip.php\",\"limitEC=".$lim."&limitPas=".$limitPas.$get2."\",\"\")'>[".($j+1)."-".($j+$limitPas)."]</a>");
    else
    print("<a href='#' class='pagination' onclick='postData(\"index.php\",\"limitEC=".$lim."&limitPas=".$limitPas.$get2."\",\"act=financements\")'>[".($j+1)."-".($j+$limitPas)."]</a>");
    }
    else
    print("<b class='ici'>  [".($j+1)."-".($j+$limitPas)."] </b>");

    }

    //-----Suivant
    if($limitEC+$limitPas<count($tab)-1){
    $lim=$limitEC+$limitPas;

    if ( (stristr($_SERVER['PHP_SELF'], 'control') === FALSE) )
    print("<a href='#' class='pagination' onclick='postData(\"spip.php\",\"limitEC=".$lim."&limitPas=".$limitPas.$get2."\",\"\")'>Suivant <IMG src='".$chm."IMG/droite_seul.gif' width='6' height='8' alt='Suivant' /></a>");
    else
    print("<a href='#' class='pagination' onclick='postData(\"index.php\",\"limitEC=".$lim."&limitPas=".$limitPas.$get2."\",\"act=financements\")'>Suivant <IMG src='".$chm."IMG/droite_seul.gif' width='6' height='8' alt='Suivant' /></a>");
    }
    //-----Fin
    if($limitEC+(2*$limitPas)<count($tab)-1){
    $lim=intval(count($tab)/$limitPas)*$limitPas;
    if($lim==count($tab) && $lim-$limitPas>0)
    $lim-=$limitPas;

    if ( (stristr($_SERVER['PHP_SELF'], 'control') === FALSE) )
    print("<a href='#' class='pagination' onclick='postData(\"spip.php\",\"limitEC=".$lim."&limitPas=".$limitPas.$get2."\",\"\")'>Fin <IMG src='".$chm."IMG/grosse_puce_fleche.gif' width='11' height='8' alt='Fin' /></a>");
    else
    print("<a href='#' class='pagination' onclick='postData(\"index.php\",\"limitEC=".$lim."&limitPas=".$limitPas.$get2."\",\"act=financements\")'>Fin <IMG src='".$chm."IMG/grosse_puce_fleche.gif' width='11' height='8' alt='Fin' /></a>");
    }

    print("</div>\n");
    }
    }
    0
  2. youplaboum
     
    merci bokou
    jsuis pas couché
    0
  3. Utilisateur anonyme
     
    désolé c'est une vielle fonction que j'ai fais avec un collègue ya un peu de trie a faire mais bon
    genre les test : if ( (stristr($_SERVER['PHP_SELF'], 'control') === FALSE) )

    tu peu les degager je pense
    et puis je passe des valeur avec une fonction f_post_data tu ten fou aussi de sa passe tes info normalement :) si ta besoin d'aide esite pas!
    0