IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Afficher 5 produits par ligne


Sujet :

PHP & Base de données

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut Afficher 5 produits par ligne
    Bonjour à tous,

    Ce thème à sûrement déjà été abordé, mais je n’ai rien trouvé.
    Voilà mon PB j’ai un catalogue de produit à afficher, ce catalogue est réparti en catégorie.
    Quand je sélectionne une catégorie j’affiche les produits de cette dernière. Jusque là c’est bon. Mais là ou ça devient plus chaud pour moi c’est quand ma catégorie contient plus de 5 produits. En effet, mon affichage ne passe pas à la ligne automatiquement. Je me doute que je dois utiliser le modulo quelque chose dans ce genre mais je n’y arrive pas. Je vous donne le liens de la page et le code en copie.
    Merci pour le coup de main.
    http://www.facitic.fr/boutique/index.php?IdCat=7

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    <?php
    require ('haut.php');
    require ('../menu.php'); 
    require ('../news.php'); 
    $sql_prod ="SELECT * FROM produits WHERE Publier='1' AND FamilleProd = '".$_GET['IdCat']."'";
    //stock dans la variable des fiches et de la table à consulter
    $query_prod = mysql_query($sql_prod); //envoie de la variable stocké
    $print_prod = mysql_fetch_array($query_prod);
    //$result = mysql_num_rows($query_prod);// pour conpter les fiches de la catégorie selectionner
    //requette de selection de IdCat correspondant à FamilleProd
    $sql_familleprod ="SELECT * FROM produits_cat WHERE IdCat = '".$print_prod['FamilleProd']."'";
             $query_familleprod = mysql_query($sql_familleprod);
             $print_familleprod = mysql_fetch_array($query_familleprod);
        	?>
    <div id="corps">
    <h3> Notre Catalogue Produits : <?php echo $print_familleprod['NomCat']?></h3>
    <br /><?php //echo $result; ?>
    <br />
    <?php 
     
    	echo '<table align="center" border="0">';
        echo '<tr>';
     	while ($print_prod = mysql_fetch_array($query_prod)){
     
    	echo '<td align="center"><strong>' .$print_prod['NomProd'].'</strong> <br/><a href="../boutique/ficheproduits.php?IdProd='.$print_prod['IdProd'].'"><img src="../boutique/img/'.$print_prod['ImgProd'].'" alt="'.$print_prod['NomProd'].' ref : '.$print_prod['RefProd'].'"/></a><br/><strong>'.number_format($print_prod['Puht']*1.196,2,',', ' ').' € TC</strong></td>';
     number_format($print_prod['Puht']*1.196,2,',', ' ').' € TC</strong></td>';
      }//endwhile;
          echo '</tr>';
        echo '</table> ';
     
    ?>
    <table align="center" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td ><img src="../i/anim/bouton_infos.gif" /></td>
      </tr>
    </table>
    <br />
    <br />
    </div>
    <?php require ('../pied.php'); ?>
    Fichiers attachés Fichiers attachés

  2. #2
    Membre averti
    Avatar de phpiste
    Homme Profil pro
    Développeur Senior
    Inscrit en
    Septembre 2006
    Messages
    251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Senior
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2006
    Messages : 251
    Points : 445
    Points
    445
    Billets dans le blog
    7
    Par défaut
    Bon pour afficher une recordeset de cette façon il te faut 2 boucles une pour
    les lignes et une autre pour les td voila un code vite fait dont je ne suis pas sure

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    <?php
    //le nombre de resultat (à remplacer dans ton cas avec mysql_num_rows($query_prod )
    $nb_resultat	=52;
    //$nb_resultat	=	mysql_num_rows($query_prod );
    //tu fixe le nombre de produit par ligne 
    $nb_produit_par_ligne=5 ;
     
    //tu calcule le nombre de ligne
    $nb_ligne=($nb_produit_par_ligne !=0)?ceil($nb_resultat/$nb_produit_par_ligne):0 ;
    $k=0;
    //en suite tu fait deux boucle une pour tes td ( qui contiennet les produits )
    //et l'autre pour les lignes
     ?>
     
    <table width="100%%" border="1" cellpadding="0" cellspacing="0" bordercolor="#003366">
    <?php for($i=0;$i<$nb_ligne;$i++){?>
      <tr>
    	 <?php for($j=0;$j<$nb_produit_par_ligne;$j++){?><td><?php 
    //$k c'est l'index du produit ds le tableau dont tu doit afficher 
    if($k<$nb_resultat){echo $k ;}; $k++ ; ?></td><?php }?>
      </tr>
     <?php  }?>
    </table>
    Voila
    Je suis Développeur Senior ouvert aux opportunités
    Mon blog

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    je te remercie, je vais tester ce code dans la journée et je te tiens informé du résultat.

  4. #4
    Membre averti
    Avatar de phpiste
    Homme Profil pro
    Développeur Senior
    Inscrit en
    Septembre 2006
    Messages
    251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Senior
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2006
    Messages : 251
    Points : 445
    Points
    445
    Billets dans le blog
    7
    Par défaut
    le code a été éditer essayez la nouvelle version
    Je suis Développeur Senior ouvert aux opportunités
    Mon blog

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    OK pour le placement et le calcul du nombre de produit se fait parfaitement. il faut que j'intégre les données de ma base maintenant. si j'ai bien compris je remplace $k par les enregistrement de ma BD

  6. #6
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    SUPER !!!

    Un grand merci, ça fonctionne comme je le veux, je dois encore effecxtuer quelque réglage et tout sera parfais.
    encore merci !

  7. #7
    Membre averti
    Avatar de phpiste
    Homme Profil pro
    Développeur Senior
    Inscrit en
    Septembre 2006
    Messages
    251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Senior
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2006
    Messages : 251
    Points : 445
    Points
    445
    Billets dans le blog
    7
    Par défaut
    Un petit reglage :
    il te faut un mysql_data_seek($ton _query, $k) pour deplacer le pointeur du resultat si non tu va afficher le meme produit .
    Je suis Développeur Senior ouvert aux opportunités
    Mon blog

  8. #8
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    Oui je viens de m'en rendre compte, il faut donc que j'intégre :
    mysql_data_seek($query_prod, $k)
    Mais je le mets à quel endroit dans le code ?
    voici le lien d'une page : http://www.facitic.fr/boutique/index.php?IdCat=8
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
     <?php
    require ('haut.php');
    require ('../menu.php'); 
    require ('../news.php'); 
    $sql_prod ="SELECT * FROM produits WHERE Publier='1' AND FamilleProd = '".$_GET['IdCat']."'";
    //stock dans la variable des fiches et de la table à consulter
    $query_prod = mysql_query($sql_prod); //envoie de la variable stocké
    $print_prod = mysql_fetch_array($query_prod);
    $result = mysql_num_rows($query_prod);
    //requette de selection de IdCat correspondant à FamilleProd
    $sql_familleprod ="SELECT * FROM produits_cat WHERE IdCat = '".$print_prod['FamilleProd']."'";
             $query_familleprod = mysql_query($sql_familleprod);
             $print_familleprod = mysql_fetch_array($query_familleprod);
        	?>
    <div id="corps">
    <h3> Notre Catalogue Produits : <?php echo $print_familleprod['NomCat']?></h3>
    <br /><?php //echo $result;?>
    <br />
    <?php
    //le nombre de resultat (à remplacer dans ton cas avec mysql_num_rows($query_prod )
    //$nb_resultat	=$result;
    $nb_resultat	=	mysql_num_rows($query_prod );
    //tu fixe le nombre de produit par ligne 
    $nb_produit_par_ligne=4 ;
     
    //tu calcule le nombre de ligne
    $nb_ligne=($nb_produit_par_ligne !=0)?ceil($nb_resultat/$nb_produit_par_ligne):0 ;
    $k=0;
     
    //en suite tu fait deux boucle une pour tes td ( qui contiennet les produits )
    //et l'autre pour les lignes
     
    //teste sur $result affichage d'une phrase de remplacement si $result=0
     //echo $nb_resultat; // affichage de nb_resultat
     if ($nb_resultat ==0){
     echo '<h3>Nous sommes désolé. Cette catégorie ne contiens pas encore d\'article</h3>';
     }else{
     
     ?>
     
    <table width="100%%" border="0" cellpadding="0" cellspacing="5" bordercolor="#003366">
    <?php 
    for(
    $i=0;
    $i<$nb_ligne;
    $i++){
    ?>
      <tr>
    	 <?php for(
    	 $j=0;
    	 $j<$nb_produit_par_ligne;
    	 $j++){
    	 ?><td align="center"><?php 
    //$k c'est l'index du produit ds le tableau dont tu dois afficher 
    		if(
    		$k<$nb_resultat){
    		echo '<strong>' .$print_prod['NomProd'].'</strong> <br/><a href="../boutique/ficheproduits.php?IdProd='.$print_prod['IdProd'].'"><img src="../boutique/img/'.$print_prod['ImgProd'].'" alt="'.$print_prod['NomProd'].' ref : '.$print_prod['RefProd'].'"/></a><br/><strong>'.number_format($print_prod['Puht']*1.196,2,',', ' ').' € TC</strong>' ;
    		echo'</td>';
    		echo'<td ></td>';
    		};//endif;
    		 $k++ ; 
    		 ?>
    		 </td><?php }//endfor;?>
     
      </tr>
       <?php 
       }//endfor;
       }//endif; ?>
    </table>
    <br />
    <table align="center" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="../i/anim/bouton_infos.gif"/></td>
      </tr>
    </table>
    <br />
    <br />
    </div>
    <?php require ('../pied.php'); ?>

  9. #9
    Membre averti
    Avatar de phpiste
    Homme Profil pro
    Développeur Senior
    Inscrit en
    Septembre 2006
    Messages
    251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Senior
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2006
    Messages : 251
    Points : 445
    Points
    445
    Billets dans le blog
    7
    Par défaut
    En effet moi meme j'arrive pas à lutiliser meme apres la lecture de la doc http://www.php.net/mysql_data_seek
    Utilise plus tot le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $print_familleprod = mysql_fetch_array($query_familleprod);
    juste apres le if mysql_fetch_array va deplacer le pointeur de ton resultat .
    Je suis Développeur Senior ouvert aux opportunités
    Mon blog

  10. #10
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    moi pas comprendre, , je le mets ou le code que tu m'as donné ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     <table width="100%%" border="0" cellpadding="0" cellspacing="5" bordercolor="#003366">
    <?php 
    for(
    $i=0;
    $i<$nb_ligne;
    $i++){
    ?>
      <tr>
    	 <?php for(
    	 $j=0;
    	 $j<$nb_produit_par_ligne;
    	 $j++){
    	 ?><td align="center"><?php 
    //$k c'est l'index du produit ds le tableau dont tu dois afficher 
    		if
    		($k<$nb_resultat){ 
    		echo '<strong>' .$print_prod['NomProd'].'</strong> <br/><a href="../boutique/ficheproduits.php?IdProd='.$print_prod['IdProd'].'"><img src="../boutique/img/'.$print_prod['ImgProd'].'" alt="'.$print_prod['NomProd'].' ref : '.$print_prod['RefProd'].'"/></a><br/><strong>'.number_format($print_prod['Puht']*1.196,2,',', ' ').' € TC</strong>' ;
    		echo'</td>';
    		echo'<td ></td>';
     
    		};//endif;
    		 $k++ ; 
    		 ?>
    		 </td><?php }//endfor;?>
     
      </tr>
       <?php 
       }//endfor;
       }//endif; ?>
    </table>

  11. #11
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    je le mets entre l'acorlade et le premier echo ?

  12. #12
    Membre averti
    Avatar de phpiste
    Homme Profil pro
    Développeur Senior
    Inscrit en
    Septembre 2006
    Messages
    251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Senior
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2006
    Messages : 251
    Points : 445
    Points
    445
    Billets dans le blog
    7
    Par défaut
    oui
    Je suis Développeur Senior ouvert aux opportunités
    Mon blog

  13. #13
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    voila ce que j'ai mis, j'ai rectifié ton code qui ne changeait rien .


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
     
    <table width="100%%" border="0" cellpadding="0" cellspacing="5" bordercolor="#003366">
    <?php 
    for(
    $i=0;
    $i<$nb_ligne;
    $i++){
    ?>
      <tr>
    	 <?php for(
    	 $j=0;
    	 $j<$nb_produit_par_ligne;
    	 $j++){
    	 ?><td align="center"><?php 
    //$k c'est l'index du produit ds le tableau dont tu dois afficher 
    		if
    		($k<$nb_resultat){
    		$print_prod = mysql_fetch_array($query_prod);// tu vois c'est ICI que je l'ai mis
    		echo '<strong>' .$print_prod['NomProd'].'</strong> <br/><a href="../boutique/ficheproduits.php?IdProd='.$print_prod['IdProd'].'"><img src="../boutique/img/'.$print_prod['ImgProd'].'" alt="'.$print_prod['NomProd'].' ref : '.$print_prod['RefProd'].'"/></a><br/><strong>'.number_format($print_prod['Puht']*1.196,2,',', ' ').' € TC</strong>' ;
    		echo'</td>';
    		echo'<td ></td>';
    		};//endif;
    		 $k++ ; 
    		 ?>
    		 </td><?php }//endfor;?>
     
      </tr>
       <?php 
       }//endfor;
       }//endif; ?>
    </table>
    Sauf que maintenant il ne m'affiche pas le dernier produit comptabilisé.
    http://www.facitic.fr/boutique/index.php?IdCat=5

  14. #14
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    Pour information, la boucle ne prend pas la première fiche de chaque catégorie

  15. #15
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 12
    Points : 4
    Points
    4
    Par défaut
    Je continue à sécher sur mon affichage de produit. est ce que vous avez une autre solution ?

Discussions similaires

  1. Afficher les résultats par ligne (horizontal)
    Par SINASOFT dans le forum SQL
    Réponses: 11
    Dernier message: 29/08/2013, 15h57
  2. [MySQL] comment afficher 5 chekbox par ligne?
    Par mustapha_aim dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 19/07/2010, 10h08
  3. wxTextCtrl : afficher 20 caractère par ligne
    Par zicos dans le forum wxWidgets
    Réponses: 0
    Dernier message: 09/11/2009, 16h51
  4. [Tableaux] Afficher N images par ligne
    Par karimphp dans le forum Langage
    Réponses: 3
    Dernier message: 31/05/2006, 10h58
  5. [PHPLIB] Afficher deux enregistrements par ligne
    Par lsteamgeo dans le forum Bibliothèques et frameworks
    Réponses: 19
    Dernier message: 30/11/2005, 12h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo