Bonsoir,
j'ai donc ajouté une liste déroulante à un champs texte pour que l'utilisateur selectionne une catégorie de recherche.
Ici la liste deroulante avec les variables
Ici le $_post pour le choix de la recherche
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <td><select name="choix"> <option value="0">-- SELECTIONNEZ --</option> <option value="<?php $nom_colone = ("id"); ?>">Id</option> <option value="<?php $nom_colone = ("Catégorie"); ?>">Catéegorie</option> <option value="<?php $nom_colone = ("Produit"); ?>">Produit</option> <option value="<?php $nom_colone = ("Marque"); ?>">Marque</option> </select></td>
Lorsque je demande une recherche, par exemple : xxx, il m'affiche :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 if(isset($_POST['envoyer-recherche-approximative'])) { $nom = mysql_real_escape_string(htmlspecialchars($_POST['recherche'])); $nom_colone = mysql_real_escape_string(htmlspecialchars($_POST['choix'])); $requete= "SELECT * FROM $nom_table WHERE $nom_colone LIKE '$nom%'";
la variableYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE 'xxx%'' at line 1qui est le texte tapé par l'utilisateur dans le champs de recherche, fonctionne.
Code : Sélectionner tout - Visualiser dans une fenêtre à part '$nom%'
Cependant pour le choix de la liste deroulante, la variablene fonctionne pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part $nom_colone
Dans la liste deroulante je lui indique bien le choix :
Bref je n'arrive pas a comprendre comment relier la liste déroulante et le champs de recherche ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <option value="<?php $nom_colone = ("id"); ?>">Id</option> <option value="<?php $nom_colone = ("Catégorie"); ?>">Catéegorie</option> <option value="<?php $nom_colone = ("Produit"); ?>">Produit</option> <option value="<?php $nom_colone = ("Marque"); ?>">Marque</option>
Tout le code :
Merci d'avance.
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
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Recherche dans la table MySql</title> <style type="text/css"> <!-- .Style1 {color: #FF0000} --> </style> </head> <body> <?php /* ------------------ Connexion a la BDD avec login.php ------------------ */ require ('login.php'); $connexion = mysql_connect($hote, $login, $pass) or die("Erreur de connexion...") ; $req = mysql_select_db($bdd, $connexion) or die("Erreur de connexion...") ; /* ------------------ Table ------------------ */ $nom_table = ("alimentaire"); /* ------------------ A PARTIR D'ICI COMMANDE DU BOUTON : RECHERCHE APPROXIMATIVE ------------------ */ if(isset($_POST['envoyer-recherche-approximative'])) { $nom = mysql_real_escape_string(htmlspecialchars($_POST['recherche'])); $nom_colone = mysql_real_escape_string(htmlspecialchars($_POST['choix'])); $requete= "SELECT * FROM $nom_table WHERE $nom_colone LIKE '$nom%'"; $resultat = mysql_query($requete) or die(mysql_error()); ?> <?php if (mysql_num_rows($resultat) != 0) { echo '<div align="center"><font face="arial" size="4" color="red">Résultat de votre recherche selon : '.$nom.'. <p>Listing ! </p></font></div> '; } ?> <table width="1493" border="1"> <tr> <table width="1751" border="0"> <tr> <th width="100" bgcolor="#999999" scope="col">Id</th> <th width="150" bgcolor="#999999" scope="col">Catégorie</th> <th width="150" bgcolor="#999999" scope="col">Produit</th> <th width="150" bgcolor="#999999" scope="col">Marque</th> </tr> <?php while($ligne=mysql_fetch_array($resultat)){ ?> <tr> <th bgcolor="#CCCCCC" scope="row"><?php echo $ligne['id']?></th> <td bgcolor="#CCCCCC"><?php echo $ligne['Id']?></td> <td bgcolor="#CCCCCC"><?php echo $ligne['Catégorie']?></td> <td bgcolor="#CCCCCC"><?php echo $ligne['Produit']?></td> <td bgcolor="#CCCCCC"><?php echo $ligne['Marque']?></td> </tr> <?php //echo $ligne['id']. $ligne['Nom']."<br/>" ; } }//toute la ligne est comprise dans la boucle while ?> </table> </p> <p align="center">Recherche d'un nom dans l'annuaire alimentaire, Veuillez selectionner une catégorie de recherche et indiquer ci-dessous le nom dans le champs pour effectuer une recherche. (<span class="Style1">*</span>) Champs obligatoire. <form action="" method='post'> </p> <table align="center" border="0"> <tr> <td> </td> <td><select name="choix"> <option value="0">-- SELECTIONNEZ --</option> <option value="<?php $nom_colone = ("id"); ?>">Id</option> <option value="<?php $nom_colone = ("Catégorie"); ?>">Catéegorie</option> <option value="<?php $nom_colone = ("Produit"); ?>">Produit</option> <option value="<?php $nom_colone = ("Marque"); ?>">Marque</option> </select></td> <td> </td> </tr> <tr> <td>Recherche (<span class="Style1">*</span> )</td> <td><input type="text" name="recherche" size="20" maxlength="20" /></td> <td><input type="submit" name="envoyer-recherche-approximative" value="Rechercher"></td> </tr> </table> <p> </p> <p align="center"> <td><FORM> <INPUT TYPE="button" VALUE="Retour" onClick="history.back()"> </FORM> <p> </p> </body> </html> <?php mysql_close(); ?>
Partager