Bonsoir a tou(te)s!
Les code de chaque page est en fin de sujet.
J'ai une base de donnée avec laquelle je doit interagir. Je dois m'y connecter en PDO.
Avec une page: Lister_Appareils.php je vais lire toute la table appareils, transforme chaque ligne en un objet de type Appareil, les affiches dans un tableau grâce a un while et a la fonction magique __toString().
Cette fonction renvois une ligne de tableau (avec tr|td|etc). La dernière colonne du tableau est un lien "customizé" pour chacun d'eux (cf code appareil.class.php).
un lien ressemble à sa: <a href='Details_Appareil.php?ID='IdDeLAppareilDeLaLigne'>Voir les détails</a>
Quand on clique sur le lien ça m'envois vers la page Details_Appareil.php
Dans cette page je dois aller récupérer le compresseur qui est monté sur l'appareil dont on veut voir les détails.
Pour récupérer le BON compresseur, j'appel une fonction de ControllerAppareils.class.php et lui passe en paramètre l'ID de l'appareil que j'ai passer en paramètre dans le lien "customizé".
Sauf que ca ne marche pas. Pourquoi?? Voilà l'url que ca envois: http://localhost/ProjetPHP/Froid_ind...pareil.php?ID=
ID n'a pas de valeur! Pourtant si je fais click droit/Afficher code source de la page Lister_Appareil.php , chacun des href est le bon...
Quelqu'un peut m'aider??
Merci d'avance
CODE (desole, il y en a pas mal..):
Appareil.class.php:
ControllerAppareils.Class.php:
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 <?php class Appareil { protected $id; public function Get_ID() { return $this->id; } protected $pos; public function Get_Position() { return $this->pos; } public function Set_Position($NewPos) { $this->pos=$NewPos; return $this->pos; } protected $type; public function Get_Type() { return $this->type; } protected $ref; public function Get_Ref() { return $this->ref; } protected $dateinstall; public function Get_DateInstall() { return $this->dateinstall; } public function Set_DateInstall($NewDate) { $this->dateinstall=$NewDate; return $this->dateinstall; } public function __construct($ID,$Pos,$Type,$Ref,$Dateinstall) { $this->id=$ID; $this->pos=$Pos; $this->type=$Type; $this->ref=$Ref; $this->dateinstall=$Dateinstall; } public function __toString() { //$info= "<tr><td>$this->id</td><td>$this->ref</td><td>$this->type</td><td>$this->pos</td><td>$this->dateinstall</td><td><a href='Details_Appareil.php' value='{$this->id}' name='bite'>Voir les détails</a></td></tr>"; $info= "<tr><td>$this->id</td><td>$this->ref</td><td>$this->type</td><td>$this->pos</td><td>$this->dateinstall</td><td><a href='Details_Appareil.php?ID='{$this->id}'>Voir les détails</a></td></tr>"; return $info; }
Lister_Appareils.php:
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 <?php class ControllerAppareils { protected $PDOConnect; public function Get_PDOName() { return $this->PDOConnect; } protected $dsn; protected $user; protected $mdp; protected $request; public function __construct($dsn,$user,$mdp) { $this->dsn= $dsn; $this->user=$user; $this->mdp=$mdp; $this->PDOConnect=new PDO($this->dsn, $this->user, $this->mdp); } public function Aff_AllAppareil($TypeAppTab, $VilleAppTab,$Request=null) { //var_dump($TypeAppTab); //var_dump($VilleAppTab); $AppareilsTab= array(); switch ($Request) { case "REF": $this->request="SELECT * FROM `appareil` ORDER BY `reference`"; break; case "TYP": $this->request="SELECT * FROM `appareil` ORDER BY `TypeAppareil_idTypeAppareil`"; break; case "LOC": $this->request="SELECT * FROM `appareil` ORDER BY `Localisation_idLocalisation`"; break; case "INS": $this->request="SELECT * FROM `appareil` ORDER BY `dateInstall`"; break; default: $this->request="SELECT * FROM `appareil`"; break; } $resultApp= $this->PDOConnect->query($this->request); while (($row=$resultApp->fetch(PDO::FETCH_ASSOC))) { //var_dump($row['TypeAppareil_idTypeAppareil']); //var_dump($row['Localisation_idLocalisation']); $AppareilsTab[]=new Appareil($row['idAppareil'], $VilleAppTab["{$row['Localisation_idLocalisation']}"], $TypeAppTab["{$row['TypeAppareil_idTypeAppareil']}"], $row['reference'], $row['dateInstall']); } return $AppareilsTab; } public function Get_TypeAppareil() { $TypeApp= array(); $this->request="SELECT * FROM `typeappareil`"; $Type= $this->PDOConnect->query($this->request); //$row=$Type->fetch(PDO::FETCH_ASSOC); while (($row=$Type->fetch(PDO::FETCH_ASSOC))) { $TypeApp[$row['idTypeAppareil']]=$row['designation']; } //return $row; return $TypeApp; } public function Get_AllVille() { $VilleApp= array(); $this->request="SELECT * FROM `localisation`"; $Villes= $this->PDOConnect->query($this->request); //$row=$Villes->fetch(PDO::FETCH_ASSOC); while ($row=$Villes->fetch(PDO::FETCH_ASSOC)) { $VilleApp[$row['idLocalisation']]=$row['ville']; } //return $row; return $VilleApp; } public function Details_Appareil($App_ID=NULL) { $CompresseurTab= array(); $test="FAIL"; $this->request="SELECT * FROM `compresseur` WHERE `Appareil_idAppareil`=$App_ID"; $Compresseurs= $this->PDOConnect->query($this->request); while ($row=$Compresseurs->fetch(PDO::FETCH_ASSOC)) { $test="{$row['idCompresseur']} | {$row['Appareil_idAppareil']} | {$row['Marque_idMarque']} | {$row['reference']}"; } /*while ($row=$Compresseurs->fetch(PDO::FETCH_ASSOC)) { //$CompresseurTab=new Compresseur($row['Marque_idMarque'], $row['reference'], $appareil); $CompresseurTab=new Compresseur($row['Marque_idMarque'], $row['reference']); }*/ if($test =="FAIL") { $test="Aucun compresseur n'est monté!"; } return $test; //return $CompresseurTab; //return $CompresseurTab; } }
Details_Appareil.php:
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 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Liste des appareils</title> <link rel="stylesheet" type="text/css" href="../css/mesStyles.css" /> </head> <?php require_once '../class/Appareil.class.php'; require_once '../class/ControllerAppareils.class.php'; require_once '../inc/connect.php'; ?> <body> <div name="bandeau" id="bandeau" class="bandeau"> <form method="post" action="login.php"> <!-- METTRE CODE AFFICHER USER--> </form> <center><h1>FroidIndus</h1></center> </div> <div name="menu" id="menu" class="centre"> <a href="Ajouter_intervention.php">Ajouter une intervention.</a><br> <a href="Editer_intervention.php">Editer une intervention.</a><br> <a href="Afficher_intervention.php">Afficher une intervention.</a><br> <a href="Ajouter_Appareil.php">Ajouter un appareil.</a><br> <a href="Localisation_Appareil.php">Localiser un appareil.</a> </div> <div name="corps" id="corps" class="centre"> <form> <table> <tr> <td>ID</td> <td class="TriageApp"> <a href="Lister_AppareilsREF.php"> Référence </a> </td> <td class="TriageApp"> <a href="Lister_AppareilsTYP.php"> Type </a> </td> <td class="TriageApp"> <a href="Lister_AppareilsLOC.php"> Ville </a> </td> <td class="TriageApp"> <a href="Lister_AppareilsINS.php"> Date d'installation </a> </td> </tr> <?php $listeAppareils=new ControllerAppareils($dsn, $user, $mdp); $Appareil=$listeAppareils->Aff_AllAppareil($listeAppareils->Get_TypeAppareil(),$listeAppareils->Get_AllVille()); foreach ($Appareil as $App) { echo $App; } ?> </table> </form> </div> <div name="pied_de_page" id="pied_de_page" class="pied_de_page"> <h6>FroidIndus Contact Coordonées</h6> </div> </body> </html>
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 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <?php require_once '../class/Appareil.class.php'; require_once '../class/ControllerAppareils.class.php'; require_once '../inc/connect.php'; require_once '../class/Compresseur.class.php'; $ID_App=$_GET['ID']; $listeAppareils=new ControllerAppareils($dsn, $user, $mdp); echo $listeAppareils->Details_Appareil($ID_App); //echo $ID_App; ?> </body> </html>
Partager