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 :

Trier des données selon l'entête de colonne [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 7
    Points : 5
    Points
    5
    Par défaut Trier des données selon l'entête de colonne
    Bonjour,

    Voila, j'ai un tout petit problème de rien du tout.
    j'ai beau chercher sur les forums, et je ne trouve pas de réponse à mon problème.

    j'ai un petit tableau (http://84.101.228.160/consultation.php) tout simple qui se créer tout seul par un php.

    le tableau va gentiment chercher les valeurs stockées dans en base de données et me les affiche par ordre d'entrée.

    jusque la tout va.

    maintenant j'aimerai cliquer sur mon entête de colonne pour afficher les données par ordre croissant. en plus claire, j'ai 3 colonnes, nom premon et cp.
    j'aimerai cliquer sur "nom" pour tier les données par ordre croissant selon les noms
    la même chose avec "prenom" et "cp".

    mon code php actuel est :

    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
    <?php virtual('/Connections/root.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
     
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
     
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
     
    mysql_select_db($database_root, $root);
    $query_Recordset1 = "SELECT * FROM nom";
    $Recordset1 = mysql_query($query_Recordset1, $root) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>repertoire</title>
    </head>
     
    <body>
    <table width="52%" height="46" border="1">
      <tr>
        <td width="32%" nowrap="nowrap" height="21" class="TitleColor">nom</td>
        <td width="12%" nowrap="nowrap" class="TitleColor">prenom</td>
        <td width="56%" nowrap="nowrap" class="TitleColor">cp</td>
      </tr>
      <?php do { ?>
      <tr>
        <td nowrap="nowrap" class="ListTitleColor"><?php echo $row_Recordset1['nom']; ?></td>
        <td nowrap="nowrap" class="ListTitleColor"><?php echo $row_Recordset1['prenom']; ?></td>
        <td nowrap="nowrap" class="ListTitleColor"><?php echo $row_Recordset1['cp']; ?></td>
        </tr>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>
    comment faire

    merci de répondre en langage de non-geek
    y4 p4s qu3 d3s G33K sur t3rr3

  2. #2
    Rédacteur
    Avatar de RideKick
    Homme Profil pro
    Directeur technique
    Inscrit en
    Septembre 2006
    Messages
    5 914
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Directeur technique
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Septembre 2006
    Messages : 5 914
    Points : 12 572
    Points
    12 572
    Par défaut
    1 solution parmis tant d'autre , chaques entete contient un lien avec la variable get du champs a trier , au clique tu recharger la page en ajoutant oreder by "ta variable get" a ta requette !

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    104
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 104
    Points : 115
    Points
    115
    Par défaut
    Je n'aurais pas dit mieux, si ce n'est d'utiliser du java script (évènement onClick() )pour éviter de recharger la page...

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 7
    Points : 5
    Points
    5
    Par défaut
    en php, j'ai réussi
    en javascript je galère encore

    merci à vous deux

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 7
    Points : 5
    Points
    5
    Par défaut Avant le "resolu"
    j'ai créé deux fichier : le premier pour envoyer une valeur aux variables le deuxieme pour afficher le tableau.

    je commence avec un (http://84.101.228.160/consult.html)
    "
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <body>
    <a href="consultation3.php?order=nom&asc_desc=1">Affichage du r&eacute;pertoir </a>
    </body>
    "

    et enfin
    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
    80
    81
    82
    83
    84
    <?php virtual('/Connections/root.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
     
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
     
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
     
    mysql_select_db($database_root, $root);
    $select='nom, prenom, cp';
     
    if($asc_desc%2)
        $query_Recordset1 = "SELECT $select FROM nom order by $order ASC";
    else
        $query_Recordset1 = "SELECT $select FROM nom order by $order DESC";
     
     
    $Recordset1 = mysql_query($query_Recordset1, $root) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>repertoire</title>
    <style type="text/css">
    <!--
    .Style4 {font-size: large}
    .Style5 {color: #FFFFFF}
    -->
    </style>
    </head>
     
    <body>
    <table width="52%" height="46" border="1">
      <tr>
        <td width="32%" nowrap="nowrap" height="21" class="TitleColor">
         NOM <span class="Style5">esp</span><a href="consultation3.php?order=nom&asc_desc=1"><span class="Style4">&uarr;</span></a> <span class="Style5">esp</span>      <a href="consultation3.php?order=nom&asc_desc=2"><span class="Style4">&darr;</span></a>      </td>
        <td width="12%" nowrap="nowrap" class="TitleColor">
     
        PRENOM <span class="Style5">esp</span><a href="consultation3.php?order=prenom&asc_desc=1"><span class="Style4">&uarr;</span></a><span class="Style5">esp</span>
        <a href="consultation3.php?order=prenom&asc_desc=2"><span class="Style4">&darr;</span></a>
        </td>
        <td width="56%" nowrap="nowrap" class="TitleColor">
     
        CP <span class="Style5">esp</span><a href="consultation3.php?order=cp&asc_desc=1"><span class="Style4">&uarr;</span></a><span class="Style5">esp</span>
        <a href="consultation3.php?order=cp&asc_desc=2"><span class="Style4"> &darr;</span></a>
        </td>
      </tr>
      <?php do { ?>
      <tr>
        <td nowrap="nowrap" class="ListTitleColor"><?php echo $row_Recordset1['nom']; ?></td>
        <td nowrap="nowrap" class="ListTitleColor"><?php echo $row_Recordset1['prenom']; ?></td>
        <td nowrap="nowrap" class="ListTitleColor"><?php echo $row_Recordset1['cp']; ?></td>
        </tr>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    <p>&nbsp;</p>
    </body>
    </html>
    encore merci et a bientot dans la partie javascript

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

Discussions similaires

  1. [VA-E] trier des données avec macro VBA
    Par M@XflY dans le forum Macros et VBA Excel
    Réponses: 25
    Dernier message: 13/01/2007, 13h24
  2. [Tableaux] Trier des données avec des tableaux
    Par yobogs dans le forum Langage
    Réponses: 2
    Dernier message: 31/10/2006, 13h39
  3. Re - Trier des données par ordre d'importance
    Par popoliline dans le forum Access
    Réponses: 14
    Dernier message: 25/08/2006, 12h29
  4. Trier des données par ordre d'importance
    Par popoliline dans le forum Access
    Réponses: 19
    Dernier message: 23/08/2006, 19h42
  5. Convertir des données selon un charset defini
    Par localhost dans le forum Langage
    Réponses: 1
    Dernier message: 14/03/2006, 12h16

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