Bonjour,

Je souhaiterai pouvoir mettre un selected par défaut dans mes liste déroulante pour éviter d'avoir un affichage déstructuré à l'ouverture de ma page.

Il s'agit d'une page permettant de faire une recherche sur les pages d'un site depuis une interface d'administration. Mes listes déroulantes permettent d'avoir accès aux différents niveaux de l'arborescence du site, il y a quatre niveaux en tout. Je souhaite afficher un choix par défaut dans chaque liste déroulante pour ne pas avoir d'erreur à l'ouverture de la page comme il s'agit de listes dynamique.

Pouvez-vous m'aider ?
Merci beaucoup d'avance )


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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
 
<form name="Form_envoi" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post" id="chgniveau">
 
 
	  <table width="100%" border="0" cellspacing="2" cellpadding="2" style="font-family:Arial; font-size:12px; color:#ffffff;">
        <tr>
          <td>
 
		  <?php
$sql = "select * from pp where reference='3' order by reference asc ";
$resultat = mysql_query($sql,$conn)  or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
while ($rang= mysql_fetch_array ($resultat)){
?>
 
  <?php
    }
?>
 
<?php
$niveau1='3';
?>
 
 
 
<select name="niveau2" onChange="document.forms['chgniveau'].submit();">
  <option value="0" selected="selected">- - - Choix niveau 2 - - -</option> 
<?php
$sql2 = "select * from pp where parent='$niveau1' order by reference asc ";
$resultat2 = mysql_query($sql2,$conn)  or die('Erreur SQL !'.$sql2.'<br>'.mysql_error());
while ($rang2= mysql_fetch_array ($resultat2)){
?>
  <option value="<?php echo($rang2['reference']); ?>"<?php if ($niveau2==$rang2['reference']) { echo ' selected="selected"'; }?>><?php echo($rang2['titre']); ?></option>
 
 
 
 
 
 
<?php
    }
?>
</select>
<?php
if (!$niveau2=='0') {
$ref_page=$niveau2;
?>
 
 
 
<select name="niveau3" onChange="document.forms['chgniveau'].submit();">
  <option value="0" selected="selected">- - - Choix niveau 3 - - -</option> 
<?php
$sql3 = "select * from pp where parent=$niveau2 order by reference asc ";
$resultat3 = mysql_query($sql3,$conn)  or die('Erreur SQL !'.$sql3.'<br>'.mysql_error());
while ($rang3= mysql_fetch_array ($resultat3)){
?>
  <option value="<?php echo($rang3['reference']); ?>"<?php if ($niveau3==$rang3['reference']) { echo ' selected="selected"'; }?>><?php echo($rang3['titre']); ?></option> 
 
 
<?php
}	
?>
</select>
 
<?php
if (!$niveau3=='0') {
$ref_page=$niveau3;
?>	
 
 
 
<select name="niveau4" onChange="document.forms['chgniveau'].submit();">
  <option value="0" selected="selected">- - - Choix niveau 4 - - -</option> 
<?php
$sql4 = "select * from pp where parent=$niveau3 order by reference asc ";
$resultat4 = mysql_query($sql4,$conn)  or die('Erreur SQL !'.$sql4.'<br>'.mysql_error());
while ($rang4= mysql_fetch_array ($resultat4)){
?>
 
   <option value="<?php echo($rang4['reference']); ?>"<?php if ($niveau4==$rang4['reference']) { echo ' selected="selected"'; }?>><?php echo($rang4['titre']); ?></option> 
 
 
 
<?php
}	
?>
</select>
 
 
 
<?php
}
 
?>
 
<?php
if (!$niveau4=='0') {
$ref_page=$niveau4;
 
}
?>	
 
<?php
}
 
?>	  </td>
        </tr>
      </table>
</form>		
 
				  </div></th>
	  </tr>
 
				<tr>
				  <th colspan="7">			  </th>
	  </tr>
 
				<tr>
				  <th colspan="7">
 
 
				  <table width=973 style="padding-left:3px;border:1;color:#155a97;">
 
<tr class="Style2">
<td width="38" valign="middle" align="left" bgcolor="#155a97" style="font-family:Arial; font-size:12px; color:#ffffff;border:1px solid #AFD3F3;"><strong>Ref.</strong><span style="font-family:Arial; font-size:8px; color:#155a97;border:0;"><br />
</span></td>
<td width="661" valign="middle" align="left" bgcolor="#155a97" style="font-family:Arial; font-size:12px; color:#ffffff;border:0;border:1px solid #AFD3F3;"><strong>Titre</strong></td>
<td width="88" valign="middle" align="center" bgcolor="#155a97" style="font-family:Arial; font-size:12px; color:#ffffff;border:0;border:1px solid #AFD3F3;"><strong>CCH </strong></td>
<td width="80" align="center" bgcolor="#155a97" style="font-family:Arial; font-size:12px; color:#ffffff;border:0;border:1px solid #AFD3F3;"><strong>Vues</strong></td>
<td width="82" align="center" bgcolor="#155a97" style="font-family:Arial; font-size:12px; color:#ffffff;border:0;border:1px solid #AFD3F3;">Hits*</td>
</tr>
 
 <?php
            if (isset($_GET['ref_page'])) {
 
			$requete = "SELECT reference,titre,contador,cch FROM pp WHERE reference = '".$ref_page."'"; 
 
 
 
            $resultat = mysql_query($requete);
 
            while ($paragraphe = mysql_fetch_array($resultat)) {
 
			$id = $paragraphe['id'];
                ?>
 
				<tr>
                    <td align="left" style="font-family:Arial; font-size:12px; color:#ffffff;border:2;border-bottom:1px solid #AFD3F3;background-color:#155a97;" valign=top><?php echo strtoupper ($paragraphe['reference']); ?></td>
                    <td align="left" style="font-family:Arial; font-size:12px; color:#155a97;border:0;border:2;border-bottom:1px solid #AFD3F3;background-color:#EBF4FC;" valign=top><?php echo $paragraphe['titre']; ?></td>
					<td align="left" style="font-family:Arial; font-size:12px; color:#155a97;border:0;border:2;border-bottom:1px solid #AFD3F3;background-color:#EBF4FC;" valign=top><div align="center"><?php echo $paragraphe['cch']; ?></div>				    </td>
					<td align="left" style="font-family:Arial; font-size:12px; color:#155a97;border:0;border:2;border-bottom:1px solid #AFD3F3;background-color:#EBF4FC;" valign=top><div align="center"><?php echo $paragraphe['contador']; ?></div>				    </td>
				    <td align="left" style="font-family:Arial; font-size:12px; color:#155a97;border:0;border:2;border-bottom:1px solid #AFD3F3;background-color:#EBF4FC;" valign=top>&nbsp;
 
 
 
 
					</td>
				</tr>
 
</table>				  </th>
	  </tr>
				<tr>
				  <th style="padding-left:10px;font-family:Arial; font-size:11px; color:#155a97;border:0;border:2;border-bottom:1px solid #AFD3F3;" colspan="7"><div align="left">* Un « <strong>hit</strong> » (en français académique « <em>impact web</em> ») correspond ainsi à un fichier chargé par le navigateur. Une page web   contenant trois images correspondra donc à quatre hits. </div></th>
	  </tr>
				<tr>
				  <th colspan="7"></th>
	  </tr>
 
 
				<tr>
				  <th colspan="7"><table width="969" border="0" cellspacing="0" cellpadding="0">
                    <tr valign="top">
                      <td width="476" valign="top">
 
 
 
 
 
<table valign="top">
				<tr>
<td width="308" valign="top" align="left" bgcolor="#386996" style="font-family:Arial; font-size:13px; color:#ffffff;border:0;border:1px solid #AFD3F3;padding-left:2px;"><strong>Niveau 2 </strong>- Analytical Sciences </td>
<td width="49" valign="top" align="center" bgcolor="#386996" style="font-family:Arial; font-size:13px; color:#ffffff;border:0;border:1px solid #AFD3F3;"><strong>CCH </strong></td>
<td width="49" valign="top" align="left" bgcolor="#386996" style="font-family:Arial; font-size:13px; color:#ffffff;border:0;border:1px solid #AFD3F3;"><div align="center"><strong>Vues</strong></div></td>
<td width="34" valign="top" align="center" bgcolor="#386996" style="font-family:Arial; font-size:13px; color:#ffffff;border:0;border:1px solid #AFD3F3;">Hits*</td>
</tr>
 
 
		<?php }
            }
            ?>		
 
 
				  <?php 
//$sql = "select * from pp where niveau=1 and reference=3 and lg='en' order by orden asc ";
//$plus=1;
$sql = "select * from pp where parent=$niveau1 order by orden asc ";
$resultat = mysql_query($sql,$conn)  or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
while ($rang= mysql_fetch_array ($resultat)){ 
?>
 
      <TR>
		<TD align="left" style="font-family:Arial; font-size:12px; color:#386996;border:0;border:2;border:1px solid #AFD3F3;background-color:#DCE8F1;" valign=top>
			<?php  echo $rang['titre'] ?>&nbsp;		</TD>
		<TD align="left" style="font-family:Arial; font-size:12px; color:#386996;border:0;border:2;border:1px solid #AFD3F3;background-color:#ffffff;" valign=top><?php  echo $rang['cch'] ?>
			&nbsp;		</TD>
		<TD align="center" style="font-family:Arial; font-size:12px; color:#386996;border:0;border:2;border:1px solid #AFD3F3;background-color:#DCE8F1;" valign=top>
			&nbsp;<?php 
 
			// Evalué à vrai car $var est vide
				if (empty($rang['titre'])) {
  				echo $rang['contador']='';
				}
 
			// Evalué à vrai car $var est défini
				if (isset($rang['titre'])) {
  				echo $rang['contador'];
				}
 
			 ?>	
 
 
 
						</TD>
		<TD align="left" style="font-family:Arial; font-size:12px; color:#386996;border:0;border:2;border:1px solid #AFD3F3;background-color:#DCE8F1;" valign=top>							</TD>
 
 
 
 
 
			<?php 
}
?>
	  </tr>
</table>