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
|
<?php
echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
/* Variables de connexion : ajustez ces paramètres selon votre propre environnement */
$serveur = "aaaa";
$admin = "aaaaa";
$mdp = "aaaaa";
$base = "aaaaa";
$idr = isset($_POST['departement'])?$_POST['departement']:null;
$ics = isset($_POST['categorie'])?$_POST['categorie']:null;
?>
<div id="formulaire">
Votre departement :<br />
<?php
$connexion = mysql_pconnect($serveur, $admin, $mdp);
if($connexion != false)
{
$choixbase = mysql_select_db($base, $connexion);
$sql1 = "SELECT `id_departement`, `departement`".
" FROM `departement`".
" WHERE `id_region` = 18".
" ORDER BY `id_departement`";
$rech_departement = mysql_query($sql1);
$code_departement = array();
$departement = array();
/* On active un compteur pour les categories */
$nb_departement = 0;
if($rech_departement != false)
{
while($ligne = mysql_fetch_assoc($rech_departement))
{
array_push($code_departement, $ligne['id_departement']);
array_push($departement, $ligne['departement']);
/* On incrémente de compteur */
$nb_departement++;
}
}
?>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post" id="chgcategorie">
<select name="departement" id="departement" onchange="document.forms['chgcategorie'].submit();">
<option value="-1">- - - Choisissez votre département - - -</option>
<?php
for($i = 0; $i < $nb_departement; $i++)
{
?>
<option value="<?php echo($code_departement[$i]); ?>"<?php echo((isset($idr) && $idr == $code_departement[$i])?" selected=\"selected\"":null); ?>><?php echo($departement[$i]); ?></option>
<?php
}
?>
</select>
</form>
<?php
mysql_free_result($rech_departement);
if(isset($idr) && $idr != -1)
{
$sql2 = "SELECT `id_categorie`, `categorie`".
" FROM `categorie`".
" ORDER BY `id_categorie`;";
if($connexion != false)
{
$rech_categorie = mysql_query($sql2, $connexion);
$nd = 0;
$code_categorie = array();
$nom_categorie = array();
while($ligne_categorie = mysql_fetch_assoc($rech_categorie))
{
array_push($code_categorie, $ligne_categorie['id_categorie']);
array_push($nom_categorie, $ligne_categorie['categorie']);
$nd++;
}
?>
Votre catégorie :<br />
<select name="departement" id="departement">
<?php
for($d = 0; $d<$nd; $d++)
{
?>
<option value="<?php echo($code_categorie[$d].'-'.$nom_categorie[$d]); ?>"<?php echo((isset($categorie_selectionne) && $categorie_selectionne == $code_categorie[$d])?" selected=\"selected\"":null); ?>><?php echo($nom_categorie[$d]); ?></option>
<?php
}
?>
</select>
<?php
}
mysql_free_result($rech_categorie);
}
?>
<?php
if(isset($ics) && $ics != -1)
{
$sql3 = "SELECT `id_souscategorie`, `souscategorie`".
" FROM `sous-categorie`".
" ORDER BY `id_souscategorie`;";
if($connexion != false)
{
$rech_souscategorie = mysql_query($sql3, $connexion);
$nc = 0;
$code_souscategorie = array();
$nom_souscategorie = array();
while($ligne_souscategorie = mysql_fetch_assoc($rech_souscategorie))
{
array_push($code_souscategorie, $ligne_souscategorie['id_souscategorie']);
array_push($nom_souscategorie, $ligne_souscategorie['souscategorie']);
$nc++;
}
?>
Votre sous-catégorie :<br />
<select name="departement" id="departement">
<?php
for($c = 0; $c<$nc; $c++)
{
?>
<option value="<?php echo($code_souscategorie[$c].'-'.$nom_souscategorie[$c]); ?>"<?php echo((isset($souscategorie_selectionne) && $sous-categorie_selectionne == $code_souscategorie[$c])?" selected=\"selected\"":null); ?>><?php echo($nom_souscategorie[$c]); ?></option>
<?php
}
?>
</select>
<?php
}
mysql_free_result($rech_souscategorie);
}
?>
<?php
echo '<input type="hidden" name="departement" id="departement" value="'.$departement[$idr - 1].'"/>';
echo '<input type="hidden" name="categorie" id="categorie" value="'.$categorie[$ics - 1].'"/>';
?>
<input type="submit" name="ok" id="ok" value="envoyer" />
<?php
/* Terminé, on ferme la connexion */
mysql_close($connexion);
}
else
{
/* Si on arrive là, c'est pas bon signe, il faut vérifier les
* paramètres de connexion, mot de passe, serveur pas démarré etc... */
}
?> |
Partager