Bonjour,
Je cherche à produire un tableau des données issues de ma base, en fonction d'un choix effectué auparavant par un menu déroulant.
J'arrive à créer un tableau à partir d'une requête et aussi à faire un menu déroulant dynamique mais je ne parviens pas à articuler les deux.
Pourriez-vous me mettre sur la voie ?
Merci.
Voici mon code :
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 <?xml version="1.0" encoding="iso-8859-1"?> <!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-fr" lang="fr-fr"> <?php session_start(); $server='localhost'; $database='truc'; $user='postgres'; $pass='postgres'; $chaine_cx="host=$server dbname=$database user=$user password=$pass"; $dbconn=pg_connect($chaine_cx) or die ('Could not connect'.$chaine_cx.pg_last_error()); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <form action="" method="post" id="form" accept-charset="utf-8"> <p>Choisissez une station flore</p> <fieldset id="staflor"> <select name="staflo" id="staflore" > <option value="-1">- - - Choisissez une station flore - - -</option> <?php $sql = "SELECT id_station_flore, nom_station_flore FROM t_station_flore ORDER BY id_station_flore"; $rech_staflo = pg_query($sql) or die ('Pb requette station flore'.pg_error()); while($ligne = pg_fetch_array($rech_staflo)) { $option= '<option value="'.$ligne['id_station_flore'].'" '; if($staflo==$ligne['id_station_flore']){$option.= ' selected="selected"';} $option.=' >'.$ligne['id_station_flore'].'</option>'; echo $option; } pg_free_result($rech_staflo); ?> </select> </fieldset> <p id="bouton" > <input type="submit" name="submit" value="Ok..." /></p> </form> <?php if(isset($_POST['staflo'])){ if($_POST['staflo']==-1) { echo '<br /><font color=red><center>Vous devez choisir une station flore'; } else{ $sql = pg_query ("SELECT * FROM t_station_flore WHERE id_station_flore='".$staflo."' ORDER BY id_station_flore"); ?> <table summary="Station flore"> <caption>Station flore</caption> <tr> <th>Nom Station</th> <th>Pente</th> <th>Altitude</th> <th>Longitude</th> <th>Latitude</th> <th>ID Etude</th> <th>ID Expo</th> <th>Commentaire</th> </tr> <?php while($donnees = pg_fetch_array($sql)) { ?> <tr> <td><?php echo $donnees['nom_station_flore'];?></td> <td><?php echo $donnees['pente'];?></td> <td><?php echo $donnees['altitude'];?></td> <td><?php echo $donnees['coord_x'];?></td> <td><?php echo $donnees['coord_y'];?></td> <td><?php echo $donnees['id_etude'];?></td> <td><?php echo $donnees['id_expo'];?></td> <td><?php echo $donnees['stat_comment'];?></td> </tr> </table> <?php } }} pg_close($dbconn); ?> </body> </html>
Partager