Afficher un nb défini de produits par page
youplaboum
-
Utilisateur anonyme -
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
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
A voir également:
- Afficher un nb défini de produits par page
- Impossible de supprimer une page word - Guide
- Clé de produit windows 10 gratuit - Guide
- Afficher google en page d'accueil - Guide
- Comment imprimer un tableau excel sur une seule page - Guide
- Nb si en anglais - Guide
4 réponses
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");
}
}
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");
}
}
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!
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!