je cherche à enchainer plusieurs selects renseignés depuis une base de données :
la valeur selectionnée dans le premier menu sert de filtre dans la requête mysql qui renseigne la liste du 2 ème select,
même principe pour le 3 ème et le 4ème.
Jusque là tout va bien, j'ai mes listes bien renseignées.
Le problème est la récupération des données.
J'ai essayé sur 1 page puis en envoyant le résulatt du formulaire sur une page de traitement
La validation du formulaire envoi sur une autre page php, où je veux afficher la liste de produits sélectionnés à travers mes menus.
Je pensais pouvoir tout faire en php, mais apparement il faut que je passe par du javascript et là je suis un peu coincé.
Je joins ma dernière version avec 2 scripts, si quelqu'un peu m'aider
formulaire
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
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
 
<form method="POST" action="catalogue_list.php">
<?php
	$_SESSION['family'] = $_POST['family']; 
	$_SESSION['brand'] = $_POST['brand']; 
	$_SESSION['ss_fam'] = $_POST['ss_fam']; 
	$_SESSION['segment'] = $_POST['segment']; 
?>
    <tr class="product_title"> 
      <td><div align="center">Family</div></td>
      <td><div align="center">Brand</div></td>
      <td><div align="center">Sous-famille</div></td>
      <td><div align="center">Segment</div></td>
    </tr>
    <tr> 
      <td align="left"><div align="center"> 
          <select name="family" style="width:120;font-size:11"  OnClick="submit()">
            <? mysql_select_db('cde_access',$db);    
				  	$sqlf = "select distinct product_fam from products";
					$reqf = mysql_query($sqlf) or die('Erreur SQL !<br>'.$sqlf.'<br>'.mysql_error());
					while($products = mysql_fetch_array($reqf)){ 
					if(isset($_SESSION['family'])and $_SESSION['family'] == $products['product_fam'])  $selected = "selected"; else $selected = "";
					echo "<option value=".$products['product_fam']." ". $selected .">".$products['product_fam'];"</option>";
					}?>
          </select>
        </div></td>
      <td align="left"><div align="center"> 
          <? if (strlen($family) > 0) { 
		echo '<select name="brand" style="width:210;font-size:11"  OnClick="submit()">';
				    mysql_select_db('cde_access',$db);    
				  	$sqlb = "select distinct product_brand from products where product_fam like '". $family ."'";
					$reqb = mysql_query($sqlb) or die('Erreur SQL !<br>'.$sqlb.'<br>'.mysql_error());
					while($products = mysql_fetch_array($reqb)){ 
					if(isset($_SESSION['brand'])and $_SESSION['brand'] == $products['product_brand'])  $selected = "selected"; else $selected = "";
					echo "<option value=".$products['product_brand']." ". $selected .">".$products['product_brand'];"</option>";
					}
				}?></select>
          </div></td>
      <td align="left"><div align="center"> 
          <? if (strlen($brand) > 0 && strlen($family) > 0) {
		echo '<select name="ss_fam" style="width:210;font-size:11"  OnClick="submit()">';
					 mysql_select_db('cde_access',$db);    
				  	$sqlc = "select distinct product_ss_fam from products where product_fam like '". $family ."' and product_brand like '". $brand ."'";
					$reqc = mysql_query($sqlc) or die('Erreur SQL !<br>'.$sqlc.'<br>'.mysql_error());
					while($products = mysql_fetch_array($reqc)){ 
					if(isset($_SESSION['ss_fam'])and $_SESSION['ss_fam'] == $products['product_ss_fam'])  $selected = "selected"; else $selected = "";
					echo "<option value=".$products['product_ss_fam']." ". $selected .">".$products['product_ss_fam'];"</option>";
					}
				}?></select>
          </div></td>
      <td align="left"><div align="center"> 
          <? if (strlen($ss_fam) > 0 && strlen($brand) > 0 && strlen($family) > 0) {
		echo '<select name="segment" style="width:230;font-size:11"  OnClick="submit()">';
					mysql_select_db('cde_access',$db);    
				  	$sqls = "select distinct product_segment from products where product_fam like '". $family ."' and product_brand like '". $brand ."' and product_ss_fam like '". $ss_fam ."'";
					$reqs = mysql_query($sqls) or die('Erreur SQL !<br>'.$sqls.'<br>'.mysql_error());
					while($products = mysql_fetch_array($reqs)){ 
					if(isset($_SESSION['segment'])and $_SESSION['segment'] == $products['segment'])  $selected = "selected"; else $selected = "";
					echo "<option value=".$products['product_segment']." ". $selected .">".$products['product_segment'];"</option>";
					}
				}?></select>
          </div></td>
    </tr>
    <tr> 
      <td colspan="4"><input type="submit" value="Valider ces choix"></td>
    </tr>
  </form>
</table>
script traitement
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
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
 
<?php
	$_SESSION['family'] = $_POST['family']; 
	$_SESSION['brand'] = $_POST['brand']; 
	$_SESSION['ss_fam'] = $_POST['ss_fam']; 
	$_SESSION['segment'] = $_POST['segment']; 
?>
 
<p><br>
</p>
<table border="1" bgcolor="cccccc" align="center" width="75%" cellpadding="0" cellspacing="0">
<tr bgcolor="white" class="panier_title">
<td width="100">&nbsp;</td>
<td width="100">AT reference</td>
<td width=''>designation</td>
<td width="80">Garo price</td>
<td width="80">FOB price</td>
<td width='100'>Quantity</td>
<td width="45">&nbsp;</td>
</tr>
<?php 
if(!isset($_SESSION['ss_fam'])){// pas de variable dans l'url
echo $_POST['family'];echo $_POST['brand'];echo $_POST['ss_fam'];echo $_POST['segment'];
mysql_select_db('cde_access',$db);   
$sql="select distinct p.product_id,p.product_ref,p.product_designation,p.product_garo_price,p.product_fob_price,p.product_code_life,p.product_fam,p.product_brand,p.product_ss_fam,p.product_segment from products p, products_attributes pa where p.product_fam like '".$_SESSION['family']."' and product_brand like '".$_SESSION['brand']."' and p.product_ss_fam like '".$_SESSION['ss_fam']."'";
$req=mysql_query($sql)or exit ('Erreur SQL !'.$sql.'<br>'.mysql_error());
while( $data=mysql_fetch_array($req) ) {//la boucle pour l'affichage des données.
echo"<tr class='panier'>
<td width='100'><a href='article_sheet.php' target='_blank'><img src='images/".$data['product_img']."' width='100' height='100' border='0'></a></td>
<td width='100'>".$data['product_ref']." </td>
<td width=''><a href='article_sheet.php' target='_blank'> ".$data['product_designation']."</a></td>
<td width='80'>".$data['product_garo_price']." </td>
<td width='80'>".$data['product_fob_price']." </td>
<td width='100'><input type='text' name='qte' size='7'></td>
<td width='45'> <a href='catalogue.php?prod=".$data['product_id']."'><img src='images/buttons/small_add.gif' border='0'></a></td>
</tr>";
}
 
mysql_close();
 
?>
</table>
<?php
}