Bonjour,
Je dois maintenir une ancienne application.
J'ai ces données en base :
COMPANY | CATEGORY | BRAND
--------------------------------
Company 1 | Category 2 | Brand A
Company 1 | Category 2 | Brand B
Company 1 | Category 2 | Brand C
Company 1 | Category 1 | Brand X
Company 1 | Category 1 | Brand Y
Company 1 | Category 1 | Brand Z
Company 1 | Category 3 | Brand A
Company 1 | Category 3 | Brand X
Je tente de les afficher sous cette forme :
- COMPANY 1
- CATEGORY 1:
- BRAND X
BRAND Y
BRAND Z
CATEGORY 2
- BRAND A
BRAND B
BRAND C
CATEGORY 3
- BRAND A
BRAND X
En php, c'est simple avec un tableau de tableaux :
Code php : 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 while ($row = mysql_fetch_assoc($result)) { $companies[$row['company']][$row['category']][] = $row['brand']; } foreach ($companies AS $company => $categories) { echo '<h2>'. htmlentities($company, ENT_COMPAT, 'UTF-8') .'</h2>'; echo '<ul>'; foreach ($categories AS $category => $brands) { echo '<li>'. htmlentities($category, ENT_COMPAT, 'UTF-8'); foreach ($brands AS $brand) { echo '<br><em>'. htmlentities($brand, ENT_COMPAT, 'UTF-8') .'</em>'; } echo '<br> </li>'; } echo '</ul>'; }
En asp, comment faire ?
Comment avoir un tableau multidimensionnel ?
Un tableau de tableaux ?
Un dictionnaire de tableaux ?
Un dictionnaire de dictionnaires ?
Partager