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 :

Tableaux indépendants en fonction du résultat requète [MySQL]


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2009
    Messages
    407
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 407
    Par défaut Tableaux indépendants en fonction du résultat requète
    Bonjour à tous,

    Dans ma page, je fais la requète suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $sql="SELECT * FROM Produit WHERE FamilleProduit='$categorie' AND Visible='O' ORDER BY SSFamilleProduit, classement";
    J'affiche ensuite les résultats dans un tableau avec le classement ORDER BY de la requete.

    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
     
    		if (isset($_GET['Categorie'])) {	
    	             $categorie=mysql_real_escape_string($_GET['Categorie']);
     
    		     $sql="SELECT * FROM Produit WHERE FamilleProduit='$categorie' AND Visible='O' ORDER BY SSFamilleProduit, classement";
                    }
    		$res_sql=mysql_query($sql)
    		     or die (mysql_error());
     
    		while($data = mysql_fetch_assoc($res_sql)) {
     
      		echo "<tr></tr>";
      		echo "<tr>";
    		echo "<td bgcolor='#abb200'><strong><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['Reference']."</a></strong></td>";
    		echo "<td><strong><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['NomProduit']."</a></strong></td>";
    		echo "<td><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['Designation']."</a></td>";
    		echo "<td align='right'><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".number_format($prix_unit_HT, 2)." €/".$data['UniteVente']."</a></td>";			
    		echo "<td align='right'><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['PrixUnitaire']." €/".$data['UniteVente']."</a></td>";
    		echo "<td align='right'><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['QteMoyen']."</a></td>";
    		echo "<td align='center'><a href='Consult_Produit.php?Reference=".$data['Reference']."'>× ".$data['QteColis']."</a></td>";
    		echo "<td align='right'><strong><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".number_format($prix_unit_TTC, 2)." €</a></strong></td>";
    		echo "<td align='right'><a href='panier.php?action=ajout&amp;r=".$data['Reference']."'><img src='/img/caddie.png' border='0' /></a></td>";
      		echo "</tr>";
    	        echo "<tr><td colspan='8'><hr width='100%' align='center'></td></tr>";
      		   }
    Je voudrais faire une boucle pour créer un tableau à chaque fois SSFamilleProduit est différent dans ma requète.

    Merci pour votre aide.

    Mikael

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Tu as juste a detecté le changement de valeur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    $SSFamilleProduit = "";
    echo '<table>';
    while($data = mysql_fetch_assoc($res_sql)) {
            if ($SSFamilleProduit != "" AND $SSFamilleProduit != $data['SSFamilleProduit']) {
                  echo '</table><table>';
    	      $SSFamilleProduit = $data['SSFamilleProduit'];
            }
      		echo "<tr></tr>";
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2009
    Messages
    407
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 407
    Par défaut
    Re,

    Merci pour ta réponse,
    mais par contre ça me mets toujours toutes mes données dans un tableau.

    Et je ne comprends pas trop ta condition, si tu pouvez m'expliquer ?

    Merci. Mikael

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Je pense que tes tableaux sont simplement collés.
    Change la ligne comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     echo '</table><p>' . $data['SSFamilleProduit'] .'</p><table>';
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2009
    Messages
    407
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 407
    Par défaut
    Alors j'avais essayé en mettant des <br/>, car je pensais aussi qu'ils étaient collés, mais c'est toujours un seul tableau.

    J'ai essayé avec ta ligne mais c'est pareil.

    Je te mets tout le code concerné, avec un peu de html (début du tableau) :

    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
     
            <div class="tableau">
    		<table cellspacing="5" class="none">
    			<tr>
      		  	      <td width="35" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000066" face="arial">R&eacute;f.</font></strong></div></td>
       		 	      <td width="300" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000066" face="arial">Produit</font></strong></div></td>
        		              <td width="450" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000066" face="arial">D&eacute;signation</font></strong></div></td>
    			      <td width="90" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000066" face="arial">Prix au kg HT</font></strong></div></td>
                                  <td width="90" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000066" face="arial">Prix au kg TTC</font></strong></div></td>
                                  <td width="50" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000066" face="arial">Poids Moyen</font></strong></div></td>
                                  <td width="50" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000066" face="arial">Condit<sup>t</sup></font></strong></div></td>
        		              <td width="50" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000066" face="arial">Total TTC approx.(*)</font></strong></div></td>
                                 <td width="20"></td>
       		 	</tr>
     
    <?php
    	while($data = mysql_fetch_assoc($res_sql)) {
                    if ($SSFamilleProduit != "" AND $SSFamilleProduit != $data['SSFamilleProduit']) {
                   echo '</table><p>' . $data['SSFamilleProduit'] .'</p><table>';
     
    	       $SSFamilleProduit = $data['SSFamilleProduit'];
            }
     
    	$prix_unit_TTC= round(($data['PrixUnitaire'] * ($data['QteMoyen']) * ($data['QteColis'])), 2);
    		    $prix_unit_HT= round((($data['PrixUnitaire'])/1.055), 2); 
     
      		    echo "<tr></tr>";
      		    echo "<tr>";
    			echo "<td bgcolor='#abb200'><strong><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['Reference']."</a></strong></td>";
    			echo "<td><strong><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['NomProduit']."</a></strong></td>";
    			echo "<td><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['Designation']."</a></td>";
    			echo "<td align='right'><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".number_format($prix_unit_HT, 2)." €/".$data['UniteVente']."</a></td>";			
    			echo "<td align='right'><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['PrixUnitaire']." €/".$data['UniteVente']."</a></td>";
    			echo "<td align='right'><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".$data['QteMoyen']."</a></td>";
    			echo "<td align='center'><a href='Consult_Produit.php?Reference=".$data['Reference']."'>× ".$data['QteColis']."</a></td>";
    			echo "<td align='right'><strong><a href='Consult_Produit.php?Reference=".$data['Reference']."'>".number_format($prix_unit_TTC, 2)." €</a></strong></td>";
    			echo "<td align='right'><a href='panier.php?action=ajout&amp;r=".$data['Reference']."'><img src='/img/caddie.png' border='0' /></a></td>";
      		    echo "</tr>";
    			echo "<tr><td colspan='8'><hr width='100%' align='center'></td></tr>";
     
      		   }
    		   ?>
    		   </table>
    Merci

  6. #6
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Je dirais que le problème se situe dans les majuscules de "SSFamilleProduit".
    Vérifie ce que contient ton $data.
    Développe avec l'affichage de toutes les erreurs, ca évite de chercher ce genre de choses.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Verrouillage d'un formulaire en fonction du résultat d'une requête
    Par jaknichan dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 02/01/2008, 10h10
  2. Réponses: 3
    Dernier message: 05/10/2007, 14h37
  3. [Tableaux] résultat requête dans une variable
    Par jedi186 dans le forum Langage
    Réponses: 4
    Dernier message: 22/02/2007, 13h43
  4. Réponses: 6
    Dernier message: 25/09/2006, 14h11
  5. [MySQL] Filtrage par ma requête sql en fonction du résultat d'un combo box
    Par digger dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 21/02/2006, 17h25

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