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
| $connexion = mysql_pconnect($serveur, $admin, $mdp);
if($connexion != false)
{
$choixbase = mysql_select_db($base, $connexion);
$sql1 = "SELECT `id_categories`, `nom`".
" FROM `categories`".
" ORDER BY `id_categories`";
$rech_cat = mysql_query($sql1);
$code_cat = array();
$cat = array();
$nb_cat = 0;
if($rech_cat != false)
{
while($ligne = mysql_fetch_assoc($rech_cat))
{
array_push($code_cat, $ligne['id_categories']);
array_push($cat, $ligne['nom']);
/* On incrémente de compteur */
$nb_cat++;
}
}
?>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post" id="chgscat">
<fieldset style="border: 3px double #333399">
<legend>choix catégorie</legend>
<select name="cat" id="cat" onchange="document.forms['chgscat'].submit();">
<option value="-1">- - - Choisissez une catégorie - - -</option>
<?php
for($i = 0; $i < $nb_cat; $i++)
{
?>
<option value="<?php echo($code_cat[$i]); ?>"<?php echo((isset($idr) && $idr == $code_cat[$i])?" selected=\"selected\"":null); ?>><?php echo($cat[$i]); ?></option>
<?php
}
?>
</select>
<?php
mysql_free_result($rech_cat);
if(isset($idr) && $idr != -1)
{
$sql2 = "SELECT `id_sous-categories`, `nom`".
" FROM `sous-categories`".
" WHERE `id_categories` = ". $idr ."".
" ORDER BY `id_sous-categories`;";
if($connexion != false)
{
$rech_scat = mysql_query($sql2, $connexion);
$nd = 0;
$code_scat = array();
$nom_scat = array();
while($ligne_scat = mysql_fetch_assoc($rech_scat))
{
array_push($code_scat, $ligne_scat['id_sous-categories']);
array_push($nom_scat, $ligne_scat['nom']);
$nd++;
}
?>
<select name="scat" id="scat">
<?php
for($d = 0; $d<$nd; $d++)
{
?>
<option value="<?php echo($code_scat[$d]); ?>"<?php echo((isset($scat_selectionne) && $scat_selectionne ==$code_scat[$d])?" selected=\"selected\"":null); ?>><?php echo($nom_scat[$d]." (". $code_scat[$d] .")"); ?></option>
<?php
}
?>
</select>
<?php
echo $cat_selectionnee = $_POST['cat']; }
mysql_free_result($rech_scat);
}
?>
<br />
<br /><input type="submit" name="ok" id="ok" value="Envoyer" />
</fieldset>
</form> |
Partager