Tri php

tridam23 Messages postés 99 Date d'inscription   Statut Membre Dernière intervention   -  
tridam23 Messages postés 99 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Est-il possible de m'aider à ajouter des tri sur ce fichier?
je souhaite donner la possibilité, en cliquant sur le tite de la colonne, la possibilité que cela tri les éléments ou les filtres?

voici le code

<?php
session_start();
if (!(isset($_SESSION['NIV']))){
    header("location:index.html");
}

require_once("connection.php");
$order = isset($_GET['order'])?$_GET['order']:'ASC';
$req = "select * from ELEVES
           ORDER BY CLASSE $order ";
$rs = mysql_query($req) or die(mysql_error());

$thOrder = $order == 'ASC'? 'DESC' : 'ASC';

?>


<html>
<head>
    <meta charset="utf-8">
<title>Affichage des élèves</title>
<link href="stle.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function imprimer(url){
  options = "Width=700,Height=700" ;
  window.open( url, "Impression", options ) ;
 }
</script>
</head>
<body>
<table width="500" border="0">
    <tr>
        <td><a href="saisieEleve.html"><br>Inscrire un élève</a></td>
        <td><a href="ChercherEleves.php"><br>Rechercher un élève</a></td>
        <td><a href="index.html"><br>Accueil</a></td>
    </tr>
</table>
<br>
<table border="1" width="50%">
    <tr>
        <th></th>
        <th>PHOTO</th>
        <th><a href="?order=<?php echo $thOrder; ?>" >CLASSE </a></th>
        <th>SECTION</th>
        <th>GROUPEMENT</th>
        <th>INSCRIPTION</th>
        <th>NOM</th>
        <th>PRENOM</th>
        <th>POSTNOM</th>
        <th>NAISSANCE</th>
        <th>SEXE</th>
        <th>NATIONALITE</th>
        <th>ADRESSE</th>
        <th>PERE</th>
        <th>TEL PERE</th>
        <th>ADRESSE DOMICILE</th>
    </tr>
    <?php while ($ET = mysql_fetch_assoc($rs)) { ?>
        <tr>
            <td><a href="detailEleve.php?code=<?php echo $ET['CODE'] ;?>" class="bouton" 
onclick="imprimer('detailEleve.php?code=<?php echo $ET['CODE'];?>') ;return false;">Imprimer</a></td>
            <td><img src="images/<?php echo($ET['PHOTO']) ?>" width="90" height="113"</td>
            <td><?php echo($ET['CLASSE']) ?></td>
            <td><?php echo($ET['SECTION']) ?></td>
            <td><?php echo($ET['GROUPEMENT']) ?></td>
            <td><?php echo($ET['INSCRIPTION']) ?></td>
            <td><?php echo($ET['NOM']) ?></td>
            <td><?php echo($ET['PRENOM']) ?></td>
            <td><?php echo($ET['POSTNOM']) ?></td>
            <td><?php echo($ET['NAISSANCE']) ?></td>
            <td><?php echo($ET['SEXE']) ?></td>
            <td><?php echo($ET['NATIONALITE']) ?></td>
            <td><?php echo($ET['ADRESSE']) ?></td>
            <td><?php echo($ET['PERE']) ?></td>
            <td><?php echo($ET['TELPERE']) ?></td>
            <td><?php echo($ET['ADRESSE1']) ?></td>
            <?php if ($_SESSION['NIV'] == 0) { ?>
                <td><a href="supprimerEleve.php?code=<?php echo($ET['CODE']) ?>" class="bouton">Supprimer</a></td>
                <td><a href="editEleve.php?code=<?php echo($ET['CODE']) ?>" class="bouton">Editer</a></td>
            <?php } ?>
        </tr>
    <?php } ?>
</table>
</body>
</html>



je souhaiterai que le tri se fasse aussi sur les colonnes "section" et "groupement"


A voir également:

2 réponses

Utilisateur anonyme
 
je dirais simplement que dans ta requête tu ajoute ORDER BY $colonne $order


$order = isset($_GET[''])?$_GET['colonne']:'CLASSE';
$req = "select * from ELEVES
ORDER BY $colonne $order ";

il suffit ensuite de simplement passer le bouton cliqué dans ton GET.


au passage, cela nécessitera de recharger la page a chaque clic. du javascript avec appels ajax, si tu sais faire, c'est mieux.

et pour finir ton php n'est pas en modèle MVC, mais a la limite ça c'est pas trop grave
0
ElementW Messages postés 4814 Date d'inscription   Statut Contributeur Dernière intervention   1 223
 
ton php n'est pas en modèle MVC
CACA! Le MVC n'est pas le modèle universel et ultime! Loin de ça même.
De plus pour un petit code c'est totalement overkill.
0
tridam23 Messages postés 99 Date d'inscription   Statut Membre Dernière intervention  
 
je suis perdu??? désolé de ce grand silence. je me suis marié et j'ai été deconnecté.
je reviens vers vous now !
0
ElementW Messages postés 4814 Date d'inscription   Statut Contributeur Dernière intervention   1 223
 
'lut, avertissement très important:
L'extension MySQL (fonctions mysql_*) est obsolète et il ne faut absolument plus s'en servir!
Change pour PDO ou MySQLi maintenant, pendant que tu es en train d'apprendre et que ton code est petit!
Ici, ton
 or die(mysql_error());
est une des gestion d'erreur parmi les plus horribles qui soient.
from human import idiocy
del idiocy
0