Bonjour,

J'essaye de faire des puces hiérarchisées avec des requêtes SQL.
Ma première requête fonctionne bien, elle m'affiche les matières.
Ma seconde par contre, m'affiche bien les chapitres mais elle me met les chapitres dans toutes les matières tandis qu'il faudrait que chaque chapitre aille dans la bonne matière.

Voici mon code PHP:
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
17
18
19
20
21
22
23
24
25
26
27
<div id="monmenu">
<ul class="niveau1">
<?php
$db=mysql_connect("localhost", "root", "");
mysql_select_db("dropdev",$db);
$result = mysql_query("SELECT matiere FROM matiere");
 
while ($row = mysql_fetch_row($result)) {
echo "<li>";
for ($i = 0; $i < count($row); $i++) 
{
echo "$row[$i]";
 
$result2 = mysql_query("SELECT chapitre FROM chapitre WHERE matiere = $i");
while ($row2 = mysql_fetch_row($result2)) {
echo "<ul><li>";
for ($j = 0; $j < count($row2); $j++) 
{
echo "$row2[$j]";
}
echo "</li></ul>";
}
}
echo "</li>";
}
?>
</div>

Ma BDD:
Code sql : 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
--
-- Base de données: `dropdev`
--
 
-- --------------------------------------------------------
 
--
-- Structure de la table `chapitre`
--
 
CREATE TABLE IF NOT EXISTS `chapitre` (
  `num_chapitre` int(11) NOT NULL AUTO_INCREMENT,
  `chapitre` varchar(20) DEFAULT NULL,
  `matiere` varchar(20) NOT NULL,
  PRIMARY KEY (`num_chapitre`),
  KEY `matiere` (`matiere`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
 
--
-- Contenu de la table `chapitre`
--
 
INSERT INTO `chapitre` (`num_chapitre`, `chapitre`, `matiere`) VALUES
(1, 'les boucles', 'Developpement'),
(2, 'les tableaux', 'developpement');
 
-- --------------------------------------------------------
 
--
-- Structure de la table `cours`
--
 
CREATE TABLE IF NOT EXISTS `cours` (
  `num_cours` int(11) NOT NULL AUTO_INCREMENT,
  `cours` varchar(20) DEFAULT NULL,
  `chapitre` varchar(20) NOT NULL,
  PRIMARY KEY (`num_cours`),
  KEY `chapitre` (`chapitre`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
-- --------------------------------------------------------
 
--
-- Structure de la table `exercice`
--
 
CREATE TABLE IF NOT EXISTS `exercice` (
  `num_exercice` int(11) NOT NULL AUTO_INCREMENT,
  `exercice` varchar(20) DEFAULT NULL,
  `chapitre` varchar(20) NOT NULL,
  PRIMARY KEY (`num_exercice`),
  KEY `chapitre` (`chapitre`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
-- --------------------------------------------------------
 
--
-- Structure de la table `matiere`
--
 
CREATE TABLE IF NOT EXISTS `matiere` (
  `code_matiere` int(11) NOT NULL AUTO_INCREMENT,
  `matiere` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`code_matiere`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
 
--
-- Contenu de la table `matiere`
--
 
INSERT INTO `matiere` (`code_matiere`, `matiere`) VALUES
(1, 'Developpement'),
(2, 'BDD'),
(3, 'PPE'),
(4, 'Francais'),
(5, 'Anglais'),
(6, 'Droit'),
(7, 'Economie'),
(8, 'Algorithme'),
(9, 'Mathematiques'),
(10, 'SI7');
 
-- --------------------------------------------------------
 
--
-- Structure de la table `prof`
--
 
CREATE TABLE IF NOT EXISTS `prof` (
  `code_prof` int(11) NOT NULL AUTO_INCREMENT,
  `nom` varchar(20) DEFAULT NULL,
  `prenom` varchar(20) DEFAULT NULL,
  `email` varchar(20) DEFAULT NULL,
  `matiere_prof` varchar(20) DEFAULT NULL,
  `mdp` varchar(20) NOT NULL,
  `fonction` varchar(20) NOT NULL,
  PRIMARY KEY (`code_prof`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
 
--
-- Contenu de la table `prof`
--
 
INSERT INTO `prof` (`code_prof`, `nom`, `prenom`, `email`, `matiere_prof`, `mdp`, `fonction`) VALUES
(1, 'test', 'test', 'test', 'test', 'test', 'utilisateur'),
(2, 'raph', 'raph', 'raph', 'raph', 'raph', 'administrateur'),
(3, 'poiuytr', 'poiuytr', 'poiuytr', 'poiuytr', 'poiuytr', '');
 
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Merci de votre aide