| 12
 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
 
 |  
<?php
echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
/* Variables de connexion : ajustez ces paramètres selon votre propre environnement */
$serveur = "localhost";
$admin   = "root";
$mdp     = "root";
$base    = "movedb";
/* On récupère si elle existe la valeur de la région envoyée par le formulaire */
$id_type = isset($_POST['type'])?$_POST['type']:null;
$id_block = isset($_POST['block'])?$_POST['block']:null;
$id_ref = isset($_POST['ref'])?$_POST['ref']:null;
$id_name = isset($_POST['name'])?$_POST['name']:null;
$id_desc = isset($_POST['desc'])?$_POST['desc']:null;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
</head>
<body style="font-family: verdana, helvetica, sans-serif; font-size: 85%">
<?php
if(isset($_POST['ok']) && isset($_POST['block']) && $_POST['block'] != ""
&& isset($_POST['ref']) && $_POST['ref'] != ""
&& isset($_POST['name']) && $_POST['name'] != ""
&& isset($_POST['desc']) && $_POST['desc'] != "")
{
    $type_selectionne = $_POST['type'];
    $block_selectionne = $_POST['block'];
    $ref_selectionne = $_POST['ref'];
    $name_selectionne = $_POST['name'];
    $desc_selectionne = $_POST['desc'];
}
?>
<h3>Trouver un block</h3>
<?php
/* On établit la connexion à MySQL avec mysql_pconnect() plutôt qu'avec mysql_connect()
*  car on aura besoin de la connexion un peu plus loin dans le script */
$connexion = mysql_connect($serveur, $admin, $mdp)
                      or die("Impossible de se connecter : " . mysql_error());
 
        $choixbase = mysql_select_db($base);
 
    $sql1 = "SELECT type".
    " FROM table_item".
    " GROUP BY type";
 
    $rech_types = mysql_query($sql1);
 
    if($rech_types != false)
    {
            $type = array();
 
            /* On active un compteur pour les types */
            $nb_types = 0;
 
        while($ligne = mysql_fetch_assoc($rech_types))
        {
            array_push($type, $ligne["type"]);
 
            /* On incrémente de compteur */
            $nb_types++;
        }
 
    }
?>
 
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post" id="chgblock">
<fieldset style="border: 3px double #333399">
<legend>Sélectionnez un type</legend>
<select name="type" id="type" onchange="document.forms['chgblock'].submit();">
  <option value="-1">- - - Choisissez un type - - -</option>
<?php
    for($i = 0; $i < $nb_types; $i++)
    {
?>
  <option value="<?php echo($type[$i]); ?>"<?php echo((isset($id_type) && $id_type == $type[$i])?" selected=\"selected\"":null); ?>><?php echo($type[$i]); ?></option>
<?php
    }
?>
</select>
<?php
    mysql_free_result($rech_types);
        mysql_close($connexion);
    /* On commence par vérifier si on a envoyé un numéro de type et le cas échéant s'il est différent de -1 */
 
    if(isset($id_type) && $id_type != -1)
    {
        /* Création de la requête pour avoir les blocks de ce type */
        $sql2 = "SELECT block".
        " FROM table_item".
        " WHERE type = '". $id_type ."'".
        " GROUP BY block;";
 
                $connexion = mysql_connect($serveur, $admin, $mdp)
                      or die("Impossible de se connecter : " . mysql_error());
 
                     $choixbase = mysql_select_db($base);
 
            $rech_blocks = mysql_query($sql2);
            /* Un petit compteur pour les blocks */
            $nb_blocks = 0;
            /* On crée deux tableaux pour les numéros et les noms des départements */
            $block = array();
            /* On va mettre les numéros et noms des départements dans les deux tableaux */
            while($ligne = mysql_fetch_assoc($rech_blocks))
            {
                array_push($block, $ligne["block"]);
                $nb_blocks++;
            }
 
            /* Maintenant on peut construire la liste déroulante */
?>
<select name="block" id="block" onchange="document.forms['chgblock'].submit();">
<option value="-1">- - - Choisissez un block - - -</option>
<?php
         for($j = 0; $j<$nb_blocks; $j++)
         {
?>
  <option value="<?php echo($block[$j]); ?>"<?php echo((isset($id_block) && $id_block == $block[$j])?" selected=\"selected\"":null); ?>><?php echo($block[$j]); ?></option>
<?php
     }
}
 
 
?>
</select>
 
<?php
    if((isset($id_block) && $id_block != -1) && (isset($id_type) && $id_type != -1))
    {
 
        $sql3 = "SELECT ref".
        " FROM table_item".
        " WHERE block = '". $id_block ."' AND type = '". $id_type ."'".
        " ORDER BY ref;";
 
    $connexion = mysql_connect($serveur, $admin, $mdp) or die("Impossible de se connecter : " . mysql_error());
 
        $choixbase = mysql_select_db($base);
 
            $rech_refs = mysql_query($sql3);
            $nb_refs = 0;
            $ref = array();
            while($ligne = mysql_fetch_assoc($rech_refs))
            {
                array_push($ref, $ligne["ref"]);
                $nb_refs++;
            }
?>
<select name="ref" id="ref" onchange="document.forms['chgblock'].submit();">
<option value="-1">- - - Choisissez une ref - - -</option>
<?php
         for($k = 0; $k<$nb_refs; $k++)
         {
?>
  <option value="<?php echo($ref[$k]); ?>"<?php echo((isset($id_ref) && $id_ref == $ref[$k])?" selected=\"selected\"":null); ?>><?php echo($ref[$k]); ?></option>
<?php
     }}
?>
</select>
 
 
 
<?php
    if((isset($id_block) && $id_block != -1) && (isset($id_type) && $id_type != -1)&& (isset($id_ref) && $id_ref != -1))
    {
 
        $sql4 = "SELECT name".
        " FROM table_item".
        " WHERE block = '". $id_block ."' AND type = '". $id_type ."'AND ref = '". $id_ref ."'".
        " ORDER BY name;";
 
    $connexion = mysql_connect($serveur, $admin, $mdp) or die("Impossible de se connecter : " . mysql_error());
 
        $choixbase = mysql_select_db($base);
 
            $rech_names = mysql_query($sql4);
            $nb_names = 0;
            $name = array();
            while($ligne = mysql_fetch_assoc($rech_names))
            {
                array_push($name, $ligne["name"]);
                $nb_names++;
            }
?>
<select name="name" id="name" onchange="document.forms['chgblock'].submit();">
<option value="-1"></option>
<?php
         for($l = 0; $l<$nb_names; $l++)
         {
?>
  <option value="<?php echo($name[$l]); ?>"<?php echo((isset($id_name) && $id_name == $name[$l])?" selected=\"selected\"":null); ?>><?php echo($name[$l]); ?></option>
<?php
}}
?>
</select> | 
Partager