Bonjour, j'ai construit un menu déroulant dynamique selon ma table MySql :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<select name="menu_dynmq" id="menu_dynmq" onChange="location.href='?nomfruitsdynmq='+this.value+'&amp;enfant=<?php echo $duree;?>';">      
<?php
echo "<option selected=\"selected\" value='null'>choisissez un critère</option>"; 
$res =   " select DISTINCT champs_tb_fruits FROM $table ORDER BY champs_tb_fruits ";
$rep =  mysql_query($res, $cnx) or die( mysql_error() ) ;
while($contenu_menu_dynmq = mysql_fetch_assoc($rep)) {
        echo '<option value="'.$contenu_menu_dynmq['champs_tb_fruits'].'"';
	if($nomfruitsdynmq==$contenu_menu_dynmq['champs_tb_fruits']){echo " selected";} // pour afficher la selectionne
	echo '>'.$contenu_menu_dynmq['champs_tb_fruits'].'</option>';
}
?>
</select>
Ça marche, mais "Deprecated: mysql_connect()..."

Donc je veux utiliser PDO... au lieu de mysql...

Voici ce que je fais, mais mon menu vide :
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
<select name="menu_dynmq" id="menu_dynmq" onChange="location.href='?nomfruitsdynmq='+this.value+'&amp;enfant=<?php echo $duree;?>';">      
<?php
echo "<option selected=\"selected\" value='null'>choisissez un critère</option>"; 
try{
	$bdd = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e){
	die('Erreur : ' . $e->getMessage());
}
$req = $bdd->prepare('SELECT DISTINCT '
	. $champs_tb_fruits.  '  
	FROM '. $table . ' ORDER BY '. $champs_tb_fruits );
while($contenu_menu_dynmq = $req->fetch()){ //??????  !!!!!!!!
	echo '<option value="'.$contenu_menu_dynmq[$champs_tb_fruits].'"';
	if($nomfruitsdynmq==$contenu_menu_dynmq[$champs_tb_fruits]){echo " selected";} // pour afficher la selectionne
	echo '>'.$contenu_menu_dynmq[$champs_tb_fruits].'</option>';
}
?>
</select>
Dans mon menu, il n'y a que "choisissez un critère"

Donc mon PDO ne marche pas...
Est-ce que c'est à cause de $req->fetch() ?

Que je dois faire ?


merci