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 :

gestion d'affichage entre deux boucle while mysql_fetch_array() [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2007
    Messages : 38
    Points : 28
    Points
    28
    Par défaut gestion d'affichage entre deux boucle while mysql_fetch_array()
    Bonjour,
    voila mon code:
    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
    $Sql= mysql_query("SELECT n.note,m.matiere_nom,e.nom,e.prenom FROM note n 
    							INNER JOIN matiere m 
    								ON m.matiere_id=n.matiere_id
    									INNER JOIN eleve e
    										ON e.eleve_id=n.eleve_id
    				ORDER BY m.matiere_nom;")or die(mysql_error());
     
     
    		$Sql2 = mysql_query("SELECT m.matiere_nom FROM note n 
    							INNER JOIN matiere m 
    								ON m.matiere_id=n.matiere_id;")or die(mysql_error());
    		while($donne2 = mysql_fetch_array($Sql2)){
    			echo $donne2['matiere_nom'].'<br>';
    		}
     
    		//boucle pour afficher 
    		while($donne = mysql_fetch_array($Sql)){
    			echo $donne['note'].'<br>';
    		}
    et sa m'affiche :
    français
    français
    français
    français
    math
    math
    math
    math
    13.0
    15.0
    15.0
    15.0
    12.0
    11.5
    11.4
    11.5
    les 4 premieres notes corresponts au francais
    et les dernieres au math
    j'aimerai savoir comment je peux afficher:
    français
    13.0
    15.0
    15.0
    15.0

    math
    12.0
    11.5
    11.4
    11.5

    je sais pas si s'est bien expliqué

    merci

  2. #2
    Membre éclairé Avatar de cadoudal56
    Profil pro
    Inscrit en
    Février 2005
    Messages
    694
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Février 2005
    Messages : 694
    Points : 779
    Points
    779
    Par défaut
    Hello,

    Essaie ceci pour voir ce que cela donne :

    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
     
    $Sql= mysql_query("SELECT n.note,m.matiere_nom,e.nom,e.prenom FROM note n
    INNER JOIN matiere m
    ON m.matiere_id=n.matiere_id
    INNER JOIN eleve e
    ON e.eleve_id=n.eleve_id
    ORDER BY e.nom, e.prenom;")or die(mysql_error());
     
    $Sql2 = mysql_query("SELECT DISTINCT m.matiere_nom FROM note n
    INNER JOIN matiere m
    ON m.matiere_id=n.matiere_id;")or die(mysql_error());
     
    while($donne2 = mysql_fetch_array($Sql2)){
    echo $donne2['matiere_nom'].'<br>';
         while($donne = mysql_fetch_array($Sql)){
             if ($donne2['matiere_nom'] == $donne['matiere_nom']) {
             echo $donne['nom'].' '.$donne['prenom'].' : '.$donne['note'].'<br>';
             }#end if
         }#end while $donne
    }#end while $donne2
    Et si cela fonctionne n'oublie pas de mettre le post en resolu

    @+
    cadou
    LMN24 - Site d'actualité internationale multilingue
    http://www.lmn24.com

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2007
    Messages : 38
    Points : 28
    Points
    28
    Par défaut
    non marche pas
    sa affiche sa :
    français
    Grand marc : 9.9
    Grand marc : 0.0
    Grand marc : 0.0
    Grand marc : 9.9
    Piton Michel : 0.0
    Piton Michel : 9.9
    Piton Michel : 0.0
    Piton Michel : 0.0
    Piton Michel : 0.0
    Piton Michel : 0.0
    Piton Michel : 0.0
    Piton Michel : 0.0
    math
    je recapitule :
    j'aimerai :

    Grand marc:

    francais:
    note1
    note2
    .....
    math:
    note1
    note2
    ....
    Piton michel:
    francais:
    note1
    note2
    ...
    math:
    note1
    note2
    ....

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2007
    Messages : 38
    Points : 28
    Points
    28
    Par défaut
    voilà j'ai trouvé la solution:
    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
    $result=mysql_fetch_array($sql);
    		$premierNom=$result['nom'];
    		$premierPrenom=$result['prenom'];
    		$premiereMatiere=$result['matiere_nom'];
    		if($premierNom=="" || $premierPrenom==""){
    			echo 'aucun élève présent dans la base de données';
    		}
    		echo '<br><font color="red"><b>'.$premierNom.'  '.$premierPrenom.'</b></font><br>';
    		echo '<b><br>'.$premiereMatiere.'</b><br>';
     
    		while($result = mysql_fetch_array($sql)){
    			$nom=$result['nom'];
    			$prenom=$result['prenom'];
    			$matiere=$result['matiere_nom'];
    			$note=$result['note'];
    			if(($nom!=$premierNom) && ($prenom!=$premierPrenom) ){
    				echo '<br><font color="red"><b>'.$nom.'  '.$prenom.'</b></font><br>';
    				$premierNom=$nom;
    				$premierPrenom=$prenom;
    				echo '<b><br>'.$matiere.'</b><br>';
    			}else if($matiere !=$premiereMatiere) {
    				echo '<b><br>'.$matiere.'</b><br>';
    				$premiereMatiere=$matiere;
    			}
    			echo $result['note'].'&nbsp;&nbsp;&nbsp;&nbsp;';
    		}
    	}

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

Discussions similaires

  1. Macro s'arretant entre deux boucles
    Par jackbauer972 dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 06/08/2007, 13h54
  2. [MySQL] Problème d'affichage dans un boucle while
    Par Yagami_Raito dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 25/05/2007, 08h31
  3. [MySQL] conflit entre deux fonction while
    Par guillaumeIOB dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 04/12/2006, 12h56
  4. Affichage entre deux tables.
    Par c@pu dans le forum Access
    Réponses: 3
    Dernier message: 02/12/2006, 11h05
  5. [MySQL] Conflit entre deux fonction WHILE
    Par guillaumeIOB dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 28/11/2006, 18h15

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