Problème de classement de moyennes [Résolu]

msi79 409 Messages postés lundi 24 août 2009Date d'inscription 5 avril 2018 Dernière intervention - 19 déc. 2017 à 22:55 - Dernière réponse : msi79 409 Messages postés lundi 24 août 2009Date d'inscription 5 avril 2018 Dernière intervention
- 26 déc. 2017 à 00:55
Bonjour,
je comprends pas pourquoi mon classement est melangé .

voici la rêquête qui est juste :
 echo $requete = "SELECT * 
            FROM tb_classement MM
			     ,inscription I
            WHERE   MM.classe = '".$classe."'
			AND     MM.id_elv = I.id_inscri
			AND     MM.id_matiere = '".$id_matiere."'
			AND     MM.perode = '{$trim}'
			AND     MM.promo = '{$promo}'
			GROUP BY MM.id_elv
			ORDER BY Moyenne DESC, MM.id_elv DESC
			";

quand je l'execute en directe en faisant :
SELECT *
 FROM tb_classement MM
          ,inscription I 
WHERE MM.classe = '3' 
AND MM.id_elv = I.id_inscri 
AND MM.id_matiere = '52' 
AND MM.perode = 'TRIM1' 
AND MM.promo = '2017-2018' 
GROUP BY MM.id_elv 
ORDER BY Moyenne DESC, MM.id_elv DESC


ca me donne :


voici tout le code :
<?php if(isset($_GET['classe'])) $classe = urldecode($_GET['classe']); ?>
<?php if(isset($_GET['promo'])) $promo = urldecode($_GET['promo']); ?>
<?php if(isset($_GET['trim'])) $trim = urldecode($_GET['trim']);

if(isset($_GET['matiere']))  $matiere = urldecode($_GET['matiere']); 
$matieres = explode("/",$matiere);
$id_matiere = $matieres["0"];
$matiere = $matieres["1"]; ?>
<?php 
// on crée la requête SQL
                            $sql = "SELECT * 
									FROM classes C
									WHERE  C.id = '".$classe."'
									 ";
//$sql = "SELECT * FROM inscription WHERE niv_act = '".$desgn."'  ORDER BY nom";
// on envoie la requête
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$res = mysql_num_rows($req);  
$rows = mysql_fetch_assoc($req);                             // 4 
?> 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>LISTE DE CLASSE</title>

    <!-- Bootstrap -->
    <link href="vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="vendors/nprogress/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="vendors/iCheck/skins/flat/green.css" rel="stylesheet">
    <!-- Datatables -->
    <link href="vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="vendors/datatables.net-buttons-bs/css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="vendors/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="vendors/datatables.net-responsive-bs/css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="vendors/datatables.net-scroller-bs/css/scroller.bootstrap.min.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="build/css/custom.min.css" rel="stylesheet">
  </head>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
            

            <!-- menu profile quick info -->
                <?php  include("menu/menu_profil.php");?>
            <!-- /menu profile quick info -->

            <br />

            <!-- sidebar menu -->
               <?php include("menu/menu.php");?>
            <!-- /sidebar menu -->

            <!-- /menu footer buttons -->
                 <?php  include("menu/footer.php"); ?>
            <!-- /menu footer buttons -->
          </div>
        </div>

        <!-- top navigation -->
                   <?php  include("menu/menu_bar.php"); ?>
        <!-- /top navigation -->

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
               
              </div>

              <div class="title_right">
                <div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
                  <div class="input-group">
                    <input type="text" class="form-control" placeholder="Search for...">
                    <span class="input-group-btn">
                      <button class="btn btn-default" type="button">Go!</button>
                    </span>
                  </div>
                </div>
              </div>
            </div>

            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>CLASSE DE <?php  echo $rows["desgn"];?>  <small>/ <?php  echo $trim;?>/MATIERE:  <?php  echo $matiere;?></small></h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                        <ul class="dropdown-menu" role="menu">
                          <li><a href="#">Settings 1</a>
                          </li>
                          <li><a href="#">Settings 2</a>
                          </li>
                        </ul>
                      </li>
                      <li><a class="close-link"><i class="fa fa-close"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                   
                    <table id="datatable-buttons" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th width="53" align="center">N°</th>
                          <th width="104" align="center">MATRICULE</th>
                          <th width="141" align='left'>NOM</th>
                          <th width="377" align='left'>PRENOMS</th>
                          <th width="49" align="center">SEXE</th>
                          <th width="45" align="center">AGE</th>
                          <th width="47" align="center">MOY </th>
                          <th width="64" align="center">RANG</th>
                         </tr>
                      </thead>

<?php

//	include('core/db/connexion.php');
	
	$moyennes = array();
	
/*	$requete = "SELECT N.id_elv
              ,N.id_matiere
			  ,N.coeff
			  ,SUM(N.note) as somme_Notes
			  ,COUNT(N.note) nb_Notes
			  ,SUM(N.note*N.coeff)/SUM(N.coeff) as moyenne
			  ,I.id_inscri 
			  ,I.matricule 
			  ,I.nom 
			  ,I.prenom 
			  ,I.sexe 
			  ,I.date_naiss 
			  ,M.groupe
		FROM notes N ,inscription I,matieres M,classes C
		WHERE   C.id = '".$classe."'
		AND     C.desgn = N.class
		AND     M.id = N.id_matiere
		AND     N.id_elv = I.id_inscri
		AND     M.matiere = '".$matiere."'
		AND     N.trim = '{$trim}'
		AND     N.annee_scol = '{$promo}'
		GROUP BY N.id_elv
		ORDER BY Moyenne DESC, N.id_elv DESC
			";*/
 echo $requete = "SELECT * 
            FROM tb_classement MM
			     ,inscription I
            WHERE   MM.classe = '".$classe."'
			AND     MM.id_elv = I.id_inscri
			AND     MM.id_matiere = '".$id_matiere."'
			AND     MM.perode = '{$trim}'
			AND     MM.promo = '{$promo}'
			GROUP BY MM.id_elv
			ORDER BY Moyenne DESC, MM.id_elv DESC
			";
			
//$query = mysql_query($sql) or die("error");
//$requete = "SELECT * FROM moyenne ORDER BY moyenne DESC";
	
	$resultat = mysql_query($requete);
	//echo  $requete;
	$i = 0;
		while( $row = mysql_fetch_array($resultat)):
	
		//echo "<h3>Moyenne de l'eleve $i : ".$row['moyenne']."</h3><br/>";
		$moyennes[] = $row['moyenne'];
		$noms[] = $row['nom'];
		$prenoms[] = $row['prenom'];
		$matricules[] = $row['matricule'];
		$sexes[] = $row['sexe'];
		$ages[] = $row['date_naiss'];
		$groupes[] = $row['groupe'];
		$coeffs[] = $row['coeff'];
		
		$i++;

	endwhile;
	
	for($b = 0; $b < $i; $b++):
		
		//echo "<h3>Moyenne de l'eleve $b : ".$moyennes[$b]."</h3><br/>";
		
	endfor;
	
	//$max = $moyennes[0];
	
	for($b = 0; $b < $i; $b++):
	
		for($c = 0; $c < $i; $c++):
		
			if($moyennes[$c+1]>$moyennes[$c]):
				$ech = $moyennes[$c+1];
				$moyennes[$c+1] = $moyennes[$c];
				$moyennes[$c] = $ech;
			endif;
	
		endfor;
	
	endfor;
	
	//echo "<hr/><br/><hr/>";
	
	$c = 1;
	
	$rangPrecedent = "";
	
	for($b = 0; $b < $i; $b++):
	
		//echo $b;
		
		
		if($b == 0):
?>
<tr style="font-family:Georgia, 'Times New Roman', Times, serif; font-size:14px; ">
      <td width="53" align="center"><?php  echo $c;?></td>
      <td width="104" align="center"><?php echo $matricules[$b];  ?></td>
      <td width="141" align="left"><?php  echo $noms[$b]; ?></td>
      <td width="377" align='left'><?php echo $prenoms[$b];  ?></td>
      <td width="49" align='center'><?php  echo $sexes[$b]; ?></td>
      <td width="45" align="center"><?php  echo $ages[$b]; ?></td>
      <td width="47" align="center"><?php  $classement = number_format($moyennes[$b],2); echo $classement; ?></td>
      <td width="64" align="center"><?php  echo $c ." er" ?> </td>
      
  </tr>
  
<?php   
$rangPrecedent = $c;
		else:
			if($moyennes[$b-1] == $moyennes[$b]):
?>
<tr style="font-family:Georgia, 'Times New Roman', Times, serif; font-size:14px; ">
      <td width="53" align="center"><?php  echo $c;?></td>
    <td width="104" align="center"><?php echo $matricules[$b];  ?></td>
      <td width="141" align="left"><?php  echo $noms[$b]; ?></td>
      <td width="377" align='left'><?php echo $prenoms[$b];  ?></td>
      <td width="49" align='center'><?php  echo $sexes[$b]; ?></td>
      <td width="45" align="center"><?php  echo $ages[$b]; ?></td>
      <td width="47" align="center"><?php  $classement = number_format($moyennes[$b],2); echo $classement; ?></td>
      <td width="64" align="center"><?php  echo $rangPrecedent ." ex " ?> </td>
      
  </tr>
			
<?php 

			else:
?>
<tr style="font-family:Georgia, 'Times New Roman', Times, serif; font-size:14px; ">
      <td width="53" align="center"><?php  echo $c;?></td>
    <td width="104" align="center"><?php echo $matricules[$b];  ?></td>
      <td width="141" align="left"><?php  echo $noms[$b]; ?></td>
      <td width="377" align='left'><?php echo $prenoms[$b];  ?></td>
      <td width="49" align='center'><?php  echo $sexes[$b]; ?></td>
      <td width="45" align="center"><?php  echo $ages[$b]; ?></td>
      <td width="47" align="center"><?php  $classement = number_format($moyennes[$b],2); echo $classement; ?></td>
      <td width="64" align="center"><?php  echo $c ." e " ?> </td>
      
  </tr>

<?php 


				$rangPrecedent = $c;
			endif;
		endif;
		
		$c++;
		
	endfor;
	


?>

                 </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
          <?php  include("menu/footer2.php"); ?>
        <!-- /footer content -->
      </div>
    </div>

    <!-- jQuery -->
    <script src="vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
  <script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
  <script src="vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
  <script src="vendors/nprogress/nprogress.js"></script>
    <!-- iCheck -->
  <script src="vendors/iCheck/icheck.min.js"></script>
    <!-- Datatables -->
  <script src="vendors/datatables.net/js/jquery.dataTables.min.js"></script>
  <script src="vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
  <script src="vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
  <script src="vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
  <script src="vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
  <script src="vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
  <script src="vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
  <script src="vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
  <script src="vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
  <script src="vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
  <script src="vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
  <script src="vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
  <script src="vendors/jszip/dist/jszip.min.js"></script>
  <script src="vendors/pdfmake/build/pdfmake.min.js"></script>
  <script src="vendors/pdfmake/build/vfs_fonts.js"></script>

    <!-- Custom Theme Scripts -->
  <script src="../build/js/custom.min.js"></script>

    <!-- Datatables -->
  <script>
      $(document).ready(function() {
        var handleDataTableButtons = function() {
          if ($("#datatable-buttons").length) {
            $("#datatable-buttons").DataTable({
              dom: "Bfrtip",
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
          }
        };

        TableManageButtons = function() {
          "use strict";
          return {
            init: function() {
              handleDataTableButtons();
            }
          };
        }();

        $('#datatable').dataTable();

        $('#datatable-keytable').DataTable({
          keys: true
        });

        $('#datatable-responsive').DataTable();

        $('#datatable-scroller').DataTable({
          ajax: "js/datatables/json/scroller-demo.json",
          deferRender: true,
          scrollY: 380,
          scrollCollapse: true,
          scroller: true
        });

        $('#datatable-fixed-header').DataTable({
          fixedHeader: true
        });

        var $datatable = $('#datatable-checkbox');

        $datatable.dataTable({
          'order': [[ 1, 'asc' ]],
          'columnDefs': [
            { orderable: false, targets: [0] }
          ]
        });
        $datatable.on('draw.dt', function() {
          $('input').iCheck({
            checkboxClass: 'icheckbox_flat-green'
          });
        });

        TableManageButtons.init();
      });
    </script>
    <!-- /Datatables -->
</body>
</html>


voici un aperçu du faut classement
Afficher la suite 

2 réponses

Répondre au sujet
jordane45 20576 Messages postés mercredi 22 octobre 2003Date d'inscriptionModérateurStatut 22 avril 2018 Dernière intervention - 19 déc. 2017 à 23:44
0
Utile
1
Bonjour,

Ton souci c'est que tes moyennes ne sont pas classées c'est bien ça ???

Et donc... le souci vient de ta requête SQL ... n'est-ce pas ?
Dans ce cas... pourquoi postes tu ta question dans le forum PHP ????????????
Ca fait combien de fois que je te l'explique ?
=> Problème de requête ->> Forum SQL

Bref....
As tu essayé d'inverser l'ordre de tes ORDER BY dans ta requête ??

SELECT *
 FROM tb_classement MM
 LEFT JOIN inscription I  ON MM.id_elv = I.id_inscri 
WHERE MM.classe = '3' 
AND MM.id_matiere = '52' 
AND MM.perode = 'TRIM1' 
AND MM.promo = '2017-2018' 
GROUP BY MM.id_elv 
ORDER BY Moyenne DESC

msi79 409 Messages postés lundi 24 août 2009Date d'inscription 5 avril 2018 Dernière intervention - 26 déc. 2017 à 00:55
Bonsoir,
une fois encore merci Jordane45.
ça marche en inversant
Commenter la réponse de jordane45

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.