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] classer tableau php


Sujet :

Langage PHP

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7
    Points : 2
    Points
    2
    Par défaut [Tableaux] classer tableau php
    Bonjour,
    voila un ami a créé pour moi une page php permettant de classer dans deux tableau une base xml (une avec la liste des objets et l'autre avec pour les classer uniquement par lieux). Cela marche bien mais je voudrais classer le deuxième tableau par ordre alphabétique.


    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    <?php  // recherche dans la base xml en ignorant case et accents
    include("xml.php");
     
    $rep = dirname(__FILE__)."/";
    $url = $rep."Y.xml";
    $xml = file_get_contents($url);
     
    $base = XML_unserialize($xml);
    $a = $base[Y];
    $b = $a[U];
     
    print("<HTML><HEAD>");
    print("<meta http-equiv=\"Content-Type\" content=\"text/html; 
    	charset=iso-8859-1\">");
    print("<TITLE>MAB: Us chimiques</TITLE></HEAD><BODY>");
     
    if( $desc=="") $desc=" ";
    print("<b><font size=\"+1\">U gyu.</font> 
    Critère de sélection</b> : ");
    if ( $lister==="tout" ) {
      print ("tout.</b><br/>");
    } else {
      print ("lignes contenant <b>\"$desc\"</b><br/>");
    }
     
    $tri = rawurldecope($desc);
     
    $acc = "èéàùçâêîôûäëïöü"; $noacc = "eeaucaeiouaeiou";
    $trilow = strtolower($tri);
    $cherch = strtr($trilow,$acc,$noacc);
     
    print("<table border=\"2\" cellpadding=\"5\" cellspacing=\"0\">");
    print("<tr bgcolor=\"cyan\"><td>lieu</td><td>cope</td>
    <td>nom</td><td>origine</td><td>quantite</td><td>qualite</td></tr>");
     
    foreach( array_keys($b) as $k ){
    	$c=$b[$k];
    	$li=strtolower($c[lieu]); $lieu=strtr($li,$acc,$noacc);
    	$co=strtolower($c[cope]); $cope=strtr($co,$acc,$noacc);
    	$no=strtolower($c[nom]);  $nom =strtr($no,$acc,$noacc);
    	$or=strtolower($c[origine]);  $origine=strtr($or,$acc,$noacc);
    	$qt=strtolower($c[quantite]); $quantite=strtr($qt,$acc,$noacc);
    	$qa=strtolower($c[qualite]); $qualite=strtr($qa,$acc,$noacc);
     
    	//$pos = strpos($c[cope],$desc);
    	//if ($pos===FALSE) print("vide");
    	//print("<B>pos=$pos</B><BR/>");
    	if ( strpos($lieu,$cherch)!==FALSE
    	  or strpos($cope,$cherch)!==FALSE
    	  or strpos($nom, $cherch)!==FALSE
    	  or strpos($origine,$cherch)!==FALSE
    	  or strpos($quantite,$cherch)!==FALSE
    	  or strpos($qualite,$cherch)!==FALSE
    	  or $lister==="tout"
    	   ) {
    	   print("<tr>");
    	print("<td>$c[lieu]</td>");
    	print("<td>$c[cope]</td>");
    	print("<td>$c[nom]</td>");
    	print("<td>$c[origine]</td>");
    	print("<td>$c[quantite]</td>");
    	print("<td>$c[qualite]</td>");
    	   print("</tr>");
    	}
    }
     
    print("</table>");
     
    if ($lister==="tout") {
    $ty = array();
    foreach( array_keys($b) as $k ){
            $c=$b[$k]; $des= $c[lieu];
            if (!array_key_exists($des,$ty)){
                    $ty[$des]=1;
            } else {
                    $ty[$des]=$ty[$des]+1; 
    		}
    }
    print("<hr/><br/>");
     
    print("<table border=\"2\" cellpadding=\"5\" cellspacing=\"0\">");
    print("<tr bgcolor=\"cyan\"><td>Lieu</td>
                            <td>Nombre</td></tr>");
    foreach( array_keys($ty) as $k ){
            $c=$ty[$k]; print("<tr>"); $kh = rawurlencope($k);
    		print("<td><A href=\"selinjchi.php?desc=$kh\".>$k</A></td>");
            print("<td>$c</td>");
            print("</tr>");
    }
    print("</table>");
    print("<br/><hr/><br/>");
    }
     
    print("</BODY></HTML>\n");
    ?>
    Bonne journée et merci d'avance

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7
    Points : 2
    Points
    2
    Par défaut
    personne?

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7
    Points : 2
    Points
    2
    Par défaut
    Tiens, ceci est-il donc un problème insoluble?

  4. #4
    Membre éclairé
    Avatar de Dia_FR
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2006
    Messages
    512
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2006
    Messages : 512
    Points : 708
    Points
    708
    Par défaut
    si tu veux trier des tableaux regarde là :

    http://fr3.php.net/manual/fr/function.asort.php

    http://fr3.php.net/manual/fr/ref.array.php

    je sais pas si ça va t'aider mais franchement là j'ai pas le temps de lire ton code

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7
    Points : 2
    Points
    2
    Par défaut
    Tout d'abord Merci

    Cependant,je ne m'y connais absolument pas en php et donc la je suis perdu.

    Si une ame charitable voudrait bien me sortir de ce mauvais pas.


  6. #6
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7
    Points : 2
    Points
    2
    Par défaut
    Toujours personne?

  7. #7
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7
    Points : 2
    Points
    2
    Par défaut
    serait-je vraiment le seul qui aies ce problème?

  8. #8
    Membre éprouvé
    Profil pro
    Inscrit en
    Juin 2002
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 1 012
    Points : 1 093
    Points
    1 093
    Par défaut
    sans doute pas le seul

    mais peut-être le seul qui veut faire du php en ne connaissant absolument pas php et qui donne l'impression de ne pas vouloir le connaître

    faut peut-être regarder les liens de Dia_FR, ou demander à l'ami qui a créé la page...

Discussions similaires

  1. Réponses: 4
    Dernier message: 05/11/2008, 17h32
  2. [Tableaux] de tableau PHP à tableau Javascript
    Par Alexdezark dans le forum Langage
    Réponses: 6
    Dernier message: 16/11/2007, 18h34
  3. [Tableaux] Création tableau Php
    Par Jabbou dans le forum Langage
    Réponses: 6
    Dernier message: 02/10/2007, 11h49
  4. [Tableaux] tri tableau php
    Par billebo dans le forum Langage
    Réponses: 16
    Dernier message: 09/03/2007, 13h40
  5. [Tableaux] affichage tableau php apres requete sql count
    Par heteroclite dans le forum Langage
    Réponses: 1
    Dernier message: 13/09/2006, 20h53

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