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

Langage PHP Discussion :

[Tableaux] Tri par colonnes


Sujet :

Langage PHP

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut [Tableaux] Tri par colonnes
    Bonjour après une recherche sur le forum j ai bien trouvé plein desujet sur ca mais pas de réponse à mon problème

    En fait j ai un tableau exemple:

    NOM / PRENOM / EMAIL
    dfgdg / sdjfhd / sdofzsd
    sdjfhsd / djsfsf / sfsdfs

    En fait en cliquant sur NOM, je voudrais qui se classe par ordre alphab. puis en cliquant sur PRENOM pareil ainsi de suite.

    Aidez moi svp

    Merci d'avance

  2. #2
    Membre éclairé Avatar de nicoaix
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    571
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2004
    Messages : 571
    Par défaut
    Les données de ton tableau proviennent d'une base de données? Tu construits ton tableau comment? Utilises-tu une variable de type array?

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    Oui les données proviennent d'une base de données.

    Le tableau est fait simplement par "echo" tr td

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    et pas de varriable array

  5. #5
    Membre éclairé Avatar de nicoaix
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    571
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2004
    Messages : 571
    Par défaut
    Dans ce cas tu peux faire un truc dans ce genre:

    $order = $_GET['order'];
    if($order == ''){
    //valeur par défaut
    $order = "nom asc";
    }

    $sql = "select * from table where ... ORDER BY ".$order."";


    ....
    //Dans la ligne qui contient les titre des colonnes (nom, prenom...) met un
    //lien sur chacun d'eux comme ça:

    <a href="<?=$_SERVER['PHP_SELF']?>?order=nom asc">Nom</a>

    <a href="<?=$_SERVER['PHP_SELF']?>?order=prenom asc">Nom</a>

    <a href="<?=$_SERVER['PHP_SELF']?>?order=email asc">Nom</a>

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    merci je vais essayer

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    A mon grand regret ca marche pas moi j ai ca:

    $requete = "SELECT * FROM abonnement ORDER BY ".$order." ";
    $resultat = mysql_query ($requete);
    print("<table border='1' width='100%'>");
    print("<tr>
    <td height='20' class='texte'><b>Nom</b></td>
    <td height='20' class='texte'><b>Prenom</b></td>
    <td height='20' class='texte'><b>Adresse</b></td>
    <td height='20' class='texte'><b>Npa</b></td>
    <td height='20' class='texte'><b>Ville</b></td>
    <td height='20' class='texte'><b>Email</b></td>
    <td height='20' class='texte'><b>Téléphone</b></td>
    <td height='20' class='texte'><b>Dnaissance</b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=ancienAbo asc'>A 05-06</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=souscripteur asc'>S</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboBleu asc'>A 270</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboRouge asc'>A 200</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboVert asc'>A 140</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboBleuReduit asc'>A 215</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboRougeReduit asc'>A 160</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboVertReduit asc'>A 120</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=abo1L asc'>A 1L</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=telebanking asc'>TB</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=bv asc'>BV</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=bvRecu asc'>BVR</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=paye asc'>Payé</a></b></td>

    </tr> ");
    echo "</tr>";

    J ai essayé sans les balise PHP mais ca marche pas non plus

  8. #8
    Membre chevronné
    Profil pro
    Inscrit en
    Février 2004
    Messages
    496
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2004
    Messages : 496
    Par défaut
    Salut,

    à la place de :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    href='<?=$_SERVER['PHP_SELF']?>?order=souscripteur asc'
    Mets plutôt:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    href='<? echo $_SERVER['PHP_SELF']?>?order=souscripteur asc'

  9. #9
    Membre éclairé Avatar de nicoaix
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    571
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2004
    Messages : 571
    Par défaut
    remplace
    print("<tr>
    <td height='20' class='texte'><b>Nom</b></td>
    <td height='20' class='texte'><b>Prenom</b></td>
    <td height='20' class='texte'><b>Adresse</b></td>
    <td height='20' class='texte'><b>Npa</b></td>
    <td height='20' class='texte'><b>Ville</b></td>
    <td height='20' class='texte'><b>Email</b></td>
    <td height='20' class='texte'><b>Téléphone</b></td>
    <td height='20' class='texte'><b>Dnaissance</b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=ancienAbo asc'>A 05-06</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=souscripteur asc'>S</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboBleu asc'>A 270</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboRouge asc'>A 200</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboVert asc'>A 140</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboBleuReduit asc'>A 215</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboRougeReduit asc'>A 160</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=aboVertReduit asc'>A 120</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=abo1L asc'>A 1L</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=telebanking asc'>TB</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=bv asc'>BV</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=bvRecu asc'>BVR</a></b></td>
    <td height='20' class='texte'><b><a href='<?=$_SERVER['PHP_SELF']?>?order=paye asc'>Payé</a></b></td>

    </tr> ");

    Par
    echo"<tr>
    <td height='20' class='texte'><b>Nom</b></td>
    <td height='20' class='texte'><b>Prenom</b></td>
    <td height='20' class='texte'><b>Adresse</b></td>
    <td height='20' class='texte'><b>Npa</b></td>
    <td height='20' class='texte'><b>Ville</b></td>
    <td height='20' class='texte'><b>Email</b></td>
    <td height='20' class='texte'><b>Téléphone</b></td>
    <td height='20' class='texte'><b>Dnaissance</b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=ancienAbo asc'>A 05-06</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=souscripteur asc'>S</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=aboBleu asc'>A 270</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=aboRouge asc'>A 200</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=aboVert asc'>A 140</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=aboBleuReduit asc'>A 215</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=aboRougeReduit asc'>A 160</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=aboVertReduit asc'>A 120</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=abo1L asc'>A 1L</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=telebanking asc'>TB</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=bv asc'>BV</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=bvRecu asc'>BVR</a></b></td>
    <td height='20' class='texte'><b><a href='".$_SERVER['PHP_SELF']."?order=paye asc'>Payé</a></b></td>

    </tr> ";

  10. #10
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    c?est bon j'ai bidouiller et ca marche un peu mieux mais pas encore optimal encore un ou 2 reglages

  11. #11
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    Voilà merci pour le script...
    Juste que quand je clic sur le liens, il m'envoie pas sur la meme page mais la "home"??? la je pige pas

  12. #12
    Membre éclairé Avatar de nicoaix
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    571
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2004
    Messages : 571
    Par défaut
    C'est peut etre un problème de config de php. Tu peux dans ce cas remplacer
    ".$_SERVER['PHP_SELF']."
    par la valeur de ton url
    par exemple : http://monsite.fr/repertoire/chemin/index.php

  13. #13
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    J utilise une constante pour la page et ca semple posé problème si je remplace : /usr.php?idContenu=abonnes par /abonnes.php ca marche mais j ai plus ma mise page, y a t il un moyen de fai avec la constante?
    Voici a quoi ressemble mon lien...

    http://.../.../abonnement/usr.php?idContenu=abonnes?order=ancienAbo asc

    En tous cas merci pour le coup de main je suis pas encore expert

  14. #14
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    Quelqu un pourrais m aider a régler juste ce petit problème? Je suis désespéré
    Merci d avance

  15. #15
    Membre chevronné
    Profil pro
    Inscrit en
    Février 2004
    Messages
    496
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2004
    Messages : 496
    Par défaut
    Quand tu as plusieurs paramètres dans ton url, tu dois les séparer avec le signe '&'.

    Donc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    http://.../.../abonnement/usr.php?idContenu=abonnes?order=ancienAbo asc
    Devient
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    http://.../.../abonnement/usr.php?idContenu=abonnes&order=ancienAbo asc
    Et, perso, je séparerais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ....&order=ancienAbo asc
    En 2 paramètres:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ...&order=ancienAbo&Sens=asc

  16. #16
    Membre averti
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Par défaut
    merci beaucoup ca marche nickel

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

Discussions similaires

  1. DBGrid & Tri par colonne à partir d'une ProcStock
    Par baptx dans le forum C++Builder
    Réponses: 1
    Dernier message: 05/11/2013, 10h23
  2. Réponses: 4
    Dernier message: 20/01/2012, 11h24
  3. Tri par colonne de n'importe quel StringGrid
    Par Dionyzos dans le forum Composants VCL
    Réponses: 3
    Dernier message: 02/07/2008, 16h47
  4. datagrid tri par colonne
    Par meryem01 dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 03/10/2007, 10h43
  5. [Tableaux] Tri par prix et categorie
    Par speedylol dans le forum Langage
    Réponses: 1
    Dernier message: 30/01/2006, 11h54

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