Tri d'un tableau par ordre alpabétique

Fermé
BoBo_ALT Messages postés 5 Date d'inscription lundi 13 mars 2006 Statut Membre Dernière intervention 12 mars 2007 - 22 févr. 2007 à 10:50
Reivax962 Messages postés 3672 Date d'inscription jeudi 16 juin 2005 Statut Membre Dernière intervention 11 février 2021 - 22 févr. 2007 à 12:28
Bonjour à tous, je vous explique vite fait mon problème. Je travaille sur une IHM permettant d'afficher, à partir de fichier dns, un tableau de trois colonnes affichant, après sélection du moyen de transmission, le nom des bâtiments, leur débit (représente la bande passante en Kbps) et le débit modifié.
Bref, j'aimerai pouvoir trier les bâtiments par ordre alphabétique, sachant qu'il n'y a pas de BDD. Voici le script, désolé pour ca taille :/

<html> <head>
<link href="form.css" rel="stylesheet" type="text/css" />
<title>Modification de débit</title>
<?php
require_once('vars.php');
?>

</head>
<body bgcolor="#525A73">

<?php

/* Determination du moyen de transmission choisi */
if (isset($_POST['ChoixMoyen'])) {
// Cas ou la selection vient d'etre faite
$choix1 = $_POST['ChoixMoyen'];
}
else {
// Cas ou la selection a ete deja faite auparavant
if (isset($_GET['CM'])) {
$choix1=$_GET['CM'];
}
else {
// Initialement, on choisit par defaut ARISTOTE
$choix1 = ARISTOTE;
}
}

/* Formulaire pour la saisie du moyen de transmission */
echo '<form name="fmoyen" action="?envoi=1" Method="POST">';

if ( $choix1 == ARISTOTE ) {
echo '<input type="radio" name=ChoixMoyen value="'.ARISTOTE.'" checked

onclick="javascript:document.fmoyen.submit()">ARISTOTE<br>';
}
else {
echo '<input type="radio" name=ChoixMoyen value="'.ARISTOTE.'"

onclick="javascript:document.fmoyen.submit()">ARISTOTE<br>';
}

if ( $choix1 == ATHREIS ) {
echo '<input type="radio" name=ChoixMoyen value="'.ATHREIS.'" checked

onclick="javascript:document.fmoyen.submit()">ATHREIS<br>';
}
else {
echo '<input type="radio" name=ChoixMoyen value="'.ATHREIS.'"

onclick="javascript:document.fmoyen.submit()">ATHREIS<br>';
}
echo '</form>';

/* Formulaire pour la sélection du bâtiment */
echo '<form name="fliste" action="?envoi=2&CM='.$choix1.'" Method="POST">';

echo '<table border=2 summary="" cellpadding=3 cellspacing=2 bgcolor="#DEDEDE" bordercolor="#000000"

borderColorLight="#00C0FF" borderColorDark="#0000FF">';
echo '<th>Batiment</th>';
echo '<th>Debit actuel<br>(Kbps)</th>';
echo '<th>Choix nouveau débit<br>(Kbps)</th>';
echo '<tr>';

$total = 0;
$total1 = 0;

$premierefois = (!isset($_GET['envoi']) || ($_GET['envoi'] == 1));
/* $key correspond au batiment ; $value au débit; $total à la somme des débits.

foreach ($Debit[$choix1] as $key => $value ) {

echo '<td align=center>';
echo "$key";
echo '</td>';
echo '<td align=center>';
echo "$value";
echo '</td>';
$total1 = $total1 + $value;

if ( $premierefois ) {


echo '<td><center><select name="'."Debit_".$key.'" size="1">';
foreach ($ListeDebits as $enumval) {
if ( $enumval == $value )
echo '<option selected="'.$enumval.'">'.$enumval.'</option>';
else
echo '<option value="'.$enumval.'">'.$enumval.'</option>';
}
echo '</select></center></td>';
}
else
{
$nouveau = $_POST['Debit_'.$key];
$total = $total + $nouveau;

echo '<td><center><select name="'."Debit_".$key.'" size="1">';
foreach ($ListeDebits as $enumval) {
if ( $enumval == $nouveau )
echo '<option selected="'.$enumval.'">'.$enumval.'</option>';
else
echo '<option value="'.$enumval.'">'.$enumval.'</option>';
}

echo '</select></center></td>';
}

echo '</tr>';

}

if ( $premierefois )
$total = $total1;

echo '<th>';
echo 'Total:</th>';
echo'<th>';
echo "$total1";
echo'</th>';
echo '<th>';
echo "$total";
echo '</th>';
echo '</table>';
echo '<input type="submit" value="Modifier">';
echo '<input type="reset" value="Recommencer" onclick="javascript:document.fmoyen.submit()">';
echo '</form>';
echo '<form name="Validation" action="nouveau.php" method="post">';
echo '<input type="submit" value="Valider">';

echo '</form>';

?>
</body>
</html>


Si quelqu'un pouvait m'aider !!?? Merci, bonne journée

1 réponse

Reivax962 Messages postés 3672 Date d'inscription jeudi 16 juin 2005 Statut Membre Dernière intervention 11 février 2021 1 011
22 févr. 2007 à 12:28
Bonjour,

les problèmes de tri sont en général assez complexes, surtout si on cherche l'optimisation (qui est nécessaire en cas de tri sur beaucoup d'éléments !).

Tu peux trouver pas mal de ressources sur Internet, qui présentent les différents algorithmes. A toi, ensuite, de les implémenter en php !

http://lwh.free.fr/pages/algo/tri/tri.htm
https://fr.wikipedia.org/wiki/Algorithme_de_tri

Bon courage,

Xavier
1