Bonjour,
j'ai une BD sous MYSQL, dans laquelle j'ai deux tables reliées.
Coté Bd tout fonctionne seulement au niveau du php je m'en sors pas bien (Je suis tout nouveau).
Dans un premier temps j'ai un Formulaire qui me permet d'afficher le contenu de la 1ere comme (dans un tableau). Maintenant j'aimerai afficher le contenu de ma seconde table à partir d'un clic sur par exemple un champs du tableau de l'interface. Et là je bloque vraiment. Voici le 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 <!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" lang="fr"> <link rel="stylesheet" media="screen" type="text/css" title="fichier" href="fichier.css" /> <head> <title>Faisceaux</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php if (isset($_POST['nom_faisceau(srce)'])AND isset ($_POST['nom_faisceau(dest)']) AND isset($_POST['libelle']) AND isset($_POST['point_code']) AND isset($_POST['type_faisceau']) AND isset($_POST['type_reseau']) AND isset($_POST['nbre_circuit']) AND isset($_POST['genre']) AND isset($_POST['centre'])) // Si les variables existent { // si on a qlqe choz à choisir if(($_POST['centre']!= NULL)&&( $_POST['nom_faiceau(srce)']!= NULL) ) { mysql_connect("localhost", "root","root");//se connecter à la base de donnée mysql_select_db("correspondance"); //selection de la BD // on utilise les fonctions PHP mysql_real_escape_string et htmlspecialchars pour la sécurité $centre= mysql_real_escape_string(htmlspecialchars($_POST['centre'])); $nom_faisceau_source= mysql_real_escape_string(htmlspecialchars($_POST['nom_faisceau_source'])); //ensuite on enregistre le message mysql_close();//deconnexion de mysql } } //Que l'on ait choisi un centre ou pas //On affiche le formulaire ?> <!-- L'en-tête --> <div id="en_tete"> <p><h2>FAISCEAUX</h2></p> </div> <hr/> <!-- Le corps --> <div id="corps"> <form method="post" action="faisceaux.php"> Veuillez choisir un centre pour voir ces faisceaux :<br/> Centre: <select name="centre" id="centre"> <option value=""></option> <option value="1" >SSP1 ou MSC1</option> <option value="2" >SSP2 ou MSC2</option> <option value="3" >MSC3</option> </select> <input type="submit" value="Voir tous les faisceaux" /><br/> Recherche du faisceau par nom<br/> Nom Faisceau: <input type="text" name="nom_faisceau" value="Nom_Faisceau" /> <input type="submit" /> </form> </div> <?php if(isset($_POST['centre']) AND isset($_POST['nom_faisceau'])) { $centre=$_POST['centre']; $nom_faisceau=$_POST['nom_faisceau']; } // Maintenant on affiche tous les faisceaux du centre selectionné // On se connecte d'abord à MySQL : mysql_connect("localhost", "root", "root"); mysql_select_db("correspondance"); // On utilise la requête suivante pour récupérer les infos sur le faisceau correspondant $reponse = mysql_query("SELECT Nom_Faisceau_Source, Nom_Faisceau_Dest, Libelle, Point_code_Source, Point_Code_Dest, Type_Faisceau, Type_reseau, Genre FROM faisceau WHERE (nom_faisceau_Source = '$nom_faisceau') OR (centre_id = '$centre')" ) or die (mysql_error()); // On se déconnecte de MySQL mysql_close(); ?> <div id="voir"> <?php echo'<table border="1"><tr>'; for ($i = 0; $i < mysql_num_fields($reponse); $i++) { echo '<th>'; echo mysql_field_name($reponse, $i); echo '</th>'; } echo '</tr>'; while ($row = mysql_fetch_row($reponse)) { echo '<tr>'; for ($j = 0; $j < count($row); $j++) { echo '<td>'; echo ($row[$j] == NULL) ? '<i>NULL</i>' : '<a href="test_Mic.php">'.$row[$j].'</a>'; echo '</td>'; } echo '</tr>'; } ?> </div> </body> </html>
Partager