Bonjour
Je continu (et bientôt) fini mon programme. Je récupère un tableau de tableau grâce à la commande PDO
le résultat me donne un truc comme ca:
maintennant je cherche a obtenir un affichage qui pour chaque classe les trierais par ordre croissant et afficherais le nom du sport suivie du chiffre corespondant
exemple:
CYCLISME 4
ect...
BOXE 392
C:\wamp\www\devoir_ecole\class\sport_distrib.php:18:
array (size=3)
0 =>
array (size=12)
'ecole' => string 'ecole_A' (length=7)
0 => string 'ecole_A' (length=7)
'boxe' => string '392' (length=3)
1 => string '392' (length=3)
'football' => string '10' (length=2)
2 => string '10' (length=2)
'judo' => string '94' (length=2)
3 => string '94' (length=2)
'natation' => string '38' (length=2)
4 => string '38' (length=2)
'cyclisme' => string '4' (length=1)
5 => string '4' (length=1)
Voici le code que j'utilise :
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 sport_distrib.php <?php // selectionne les valeurs par sport trié dans l'ordre décroissant . $dbh = new PDO ('mysql:host=localhost;dbname=devoir-ecole', 'root', ''); try { $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*Sélectionne les valeurs */ $sth = $dbh->prepare("SELECT ecole, boxe, football, judo, natation, cyclisme FROM sports"); $sth->execute(); $resultat = $sth->fetchAll(); //$resultat = $sth->fetchAll(PDO::FETCH_ASSOC);// tableau de 5 tableau contenant toutes les lignes du jeu d'enregistrements } catch (PDOException $e) { echo 'Échec lors de la connexion : ' . $e->getMessage(); } var_dump($resultat); ?>
Partager