J'ai trouvé la solution voici le code source :
<script LANGUAGE="JavaScript">
function ModifierListe(code_ville)
{
lg = document.MonFormulaire.ListeVille.length;
// ON VIDE LA LISTE DES VILLES
for (i = lg - 1; i >= 0; i--)
{
document.MonFormulaire.ListeVille.options[i] = null;
}
code_pays = document.MonFormulaire.ListePays.selectedIndex;
<?php
// CONNEXION A LA BASE DE DONNEES
$id_connexion = mysql_connect("localhost","root","");
mysql_select_db("exercice") or die("Could not select database");
$sql = "SELECT code FROM demo_pays ORDER BY code";
$resultat = mysql_query($sql) or die("Query failed");
// Génération des Villes par Pays
$max_lignes = 0;
$option_max = '';
while ($enr = mysql_fetch_array($resultat)) {
$sql = "SELECT code, ville FROM demo_ville WHERE code_pays=$enr[0] ORDER BY ville";
$resultat2 = mysql_query($sql) or die("Query failed");
echo " if (document.MonFormulaire.ListePays.options[code_pays].value == ".$enr[0].") {\n";
echo " document.MonFormulaire.ListeVille.length = ".(mysql_num_rows($resultat2)).";\n";
$cpt = 0;
while ($enr2 = mysql_fetch_array($resultat2)) {
echo " document.MonFormulaire.ListeVille.options[".$cpt."].value = ".$enr2[0].";\n";
echo " document.MonFormulaire.ListeVille.options[".$cpt."].text = \"".$enr2[1]."\";\n";
echo " if (code_ville== ".$enr2[0].") document.MonFormulaire.ListeVille.options[".$cpt."].selected = true;\n";
$cpt++;
if ($cpt > $max_lignes) $max_lignes = $cpt;
if (strlen($enr2[1]) > strlen($option_max)) $option_max = $enr2[1];
}
echo " }\n";
}
?>
}
</script>
<?php
// ----------------------------------------------------------------------------
// LISTE DES PAYS
// ----------------------------------------------------------------------------
$sql = "SELECT code, pays FROM demo_pays ORDER BY pays";
$resultat = mysql_query($sql) or die("Query failed");
echo "";
echo "
PAYS : ";
echo " \n";
if (!isset($ListePays)) $ListePays = - 1;
while ($enr = mysql_fetch_array($resultat)) {
echo "".htmlspecialchars($enr[1])."\n";
}
echo " \n";
// ----------------------------------------------------------------------------
// LISTE DES VILLES
// ----------------------------------------------------------------------------
echo " VILLE : ";
echo " \n";
for ($cpt = 0; $cpt < $max_lignes; $cpt++)
echo "".ereg_replace(".", "--", $option_max)."\n";
echo " \n";
if (!isset($ListeVille)) $ListeVille = -1;
echo "<script LANGUAGE='JavaScript'>\n;ModifierListe(".$ListeVille.");\n</script>\n";
// ----------------------------------------------------------------------------
echo "
";
echo "\n";
echo "";
echo "
";
// ----------------------------------------------------------------------------
// Résultats des sélections
// ----------------------------------------------------------------------------
if (isset($_POST['ListePays']) && $_POST['ListePays'] != "") {
$sql = "SELECT pays FROM demo_pays WHERE code='".$_POST['ListePays']."'";
$resultat = mysql_query($sql) or die("Query failed");
$enr = @mysql_fetch_array($resultat);
echo $enr[0];
echo "
";
}
if (isset($_POST['ListeVille']) && $_POST['ListeVille'] != "") {
$sql = "SELECT ville FROM demo_ville WHERE code='".$_POST['ListeVille']."'";
$resultat = mysql_query($sql) or die("Query failed");
$enr = @mysql_fetch_array($resultat);
echo $enr[0];
}
?>
J'ai trouvé la solution voici le code source :
<script LANGUAGE="JavaScript">
function ModifierListe(code_ville)
{
lg = document.MonFormulaire.ListeVille.length;
// ON VIDE LA LISTE DES VILLES
for (i = lg - 1; i >= 0; i--)
{
document.MonFormulaire.ListeVille.options[i] = null;
}
code_pays = document.MonFormulaire.ListePays.selectedIndex;
<?php
// CONNEXION A LA BASE DE DONNEES
$id_connexion = mysql_connect("localhost","root","");
mysql_select_db("exercice") or die("Could not select database");
$sql = "SELECT code FROM demo_pays ORDER BY code";
$resultat = mysql_query($sql) or die("Query failed");
// Génération des Villes par Pays
$max_lignes = 0;
$option_max = '';
while ($enr = mysql_fetch_array($resultat)) {
$sql = "SELECT code, ville FROM demo_ville WHERE code_pays=$enr[0] ORDER BY ville";
$resultat2 = mysql_query($sql) or die("Query failed");
echo " if (document.MonFormulaire.ListePays.options[code_pays].value == ".$enr[0].") {\n";
echo " document.MonFormulaire.ListeVille.length = ".(mysql_num_rows($resultat2)).";\n";
$cpt = 0;
while ($enr2 = mysql_fetch_array($resultat2)) {
echo " document.MonFormulaire.ListeVille.options[".$cpt."].value = ".$enr2[0].";\n";
echo " document.MonFormulaire.ListeVille.options[".$cpt."].text = \"".$enr2[1]."\";\n";
echo " if (code_ville== ".$enr2[0].") document.MonFormulaire.ListeVille.options[".$cpt."].selected = true;\n";
$cpt++;
if ($cpt > $max_lignes) $max_lignes = $cpt;
if (strlen($enr2[1]) > strlen($option_max)) $option_max = $enr2[1];
}
echo " }\n";
}
?>
}
</script>
<?php
// ----------------------------------------------------------------------------
// LISTE DES PAYS
// ----------------------------------------------------------------------------
$sql = "SELECT code, pays FROM demo_pays ORDER BY pays";
$resultat = mysql_query($sql) or die("Query failed");
echo "";
echo "
PAYS : ";
echo " \n";
if (!isset($ListePays)) $ListePays = - 1;
while ($enr = mysql_fetch_array($resultat)) {
echo "".htmlspecialchars($enr[1])."\n";
}
echo " \n";
// ----------------------------------------------------------------------------
// LISTE DES VILLES
// ----------------------------------------------------------------------------
echo " VILLE : ";
echo " \n";
for ($cpt = 0; $cpt < $max_lignes; $cpt++)
echo "".ereg_replace(".", "--", $option_max)."\n";
echo " \n";
if (!isset($ListeVille)) $ListeVille = -1;
echo "<script LANGUAGE='JavaScript'>\n;ModifierListe(".$ListeVille.");\n</script>\n";
// ----------------------------------------------------------------------------
echo "
";
echo "\n";
echo "";
echo "
";
// ----------------------------------------------------------------------------
// Résultats des sélections
// ----------------------------------------------------------------------------
if (isset($_POST['ListePays']) && $_POST['ListePays'] != "") {
$sql = "SELECT pays FROM demo_pays WHERE code='".$_POST['ListePays']."'";
$resultat = mysql_query($sql) or die("Query failed");
$enr = @mysql_fetch_array($resultat);
echo $enr[0];
echo "
";
}
if (isset($_POST['ListeVille']) && $_POST['ListeVille'] != "") {
$sql = "SELECT ville FROM demo_ville WHERE code='".$_POST['ListeVille']."'";
$resultat = mysql_query($sql) or die("Query failed");
$enr = @mysql_fetch_array($resultat);
echo $enr[0];
}
?>