J'ai réaliser une jointure de la table user et de la table services mais j'aimerais savoir si elle est correcte et savoir ce que je peux arranger dans mon code php car la jointure ne fonctionne pas.
J'utilise le MVC multiple.
Merci d'avance.
Code HTML et PHP :
Code HTML:<div class="container"> <form action="index.php?controller=user&action=list" method="POST"> <div class="form-group"> <label for="parm0">id_user</label> <input class="form-control" id="parm0" name="parm0" type="text" readonly value="{parm0}"/> </div> <div class="form-group"> <label for="parm1">Nom</label> <input class="form-control" id="parm1" name="parm1" type="text" {readonly} value="{parm1}"/> </div> <div class="form-group"> <label for="parm2">Prénom</label> <input class="form-control" id="parm2" name="parm2" type="text" {readonly} value="{parm2}"/> </div> <div class="form-group"> <label for="id_services">id_services</label> <select name="id_services" id="id_services"> <?php const SERVER = "sqlprive-pc2372-001.p******************"; const USER = "ce***********"; const PASSWORD = "t**********"; const BASE ="c********"; $connexion = new PDO("mysql:host=" . self::SERVER . ";dbname=" . self::BASE, self::USER, self::PASSWORD); $requete = "SELECT user.id_user, user.Nom, user.Prenom, user.id_services,services.Services FROM user INNER JOIN services ON user.id_user=services.id_services"; $resultat = $connexion->query($requete); $liste = $resultat->fetchAll(PDO::FETCH_ASSOC); foreach($liste as $donnee){ $valeur = $donnee['id_services']; echo "<option value='".$valeur."'>" . $donnee['id_services'] . "</option>"; } ?> </select> </div> <div class="form-group"> <button class="btn btn-primary" type="submit" id="action" name="action" value="{action}">{lib_action}</button> </div> </form> </div>Code PHP:
<?php
class UserView {
private $page;
public function __construct(){
$this->page = $this->searchHTML('header');
$this->page .= $this->searchHTML('nav');
}
public function displayList($list){
$this->page .= "<h3>Vous êtes sur la page User</h3>";
$tableau = '<div class="container">'
. '<table class="table table-striped table-bordered" cellspacing="0">'
. '<thead>'
. '<th>Nom</th><th>Prénom</th><th>id_services</th><th>Modifier</th><th>Supprimer</th>'
. '</thead><tbody>';
foreach ($list as $ligne){
$tableau .= "<tr><td>$ligne[1]</td>"
."<td>$ligne[2]</td>"
."<td>$ligne[3]</td>"
."<td><a href='index.php?controller=user&action=formUpdate&parm0=$ligne[0]&parm1=$ligne[1]&parm2=$ligne[2]&parm3=$ligne[3]'><svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-pencil' viewBox='0 0 16 16'>
<path fill-rule='evenodd' d='M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5L13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175l-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z'/>
</svg></a></td>"
."<td><a href='index.php?controller=user&action=formDelete&parm0=$ligne[0]&parm1=$ligne[1]&parm2=$ligne[2]&parm3=$ligne[3]'><svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-trash' viewBox='0 0 16 16'>
<path d='M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z'/>
<path fill-rule='evenodd' d='M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4L4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z'/>
</svg></a></td></tr>";
}
$tableau .= "</tbody></table><a class='btn btn-primary' href='index.php?controller=user&action=add' role='button'>Ajouter un utilisateur</a></div>";
$this->page .= $tableau;
$this->display();
}
public function displayAdd(){
$this->page .= "<h3>Vous êtes sur la page d'ajout d'un utilisateur</h3>";
$paramatres = array(
"readonly"=>"",
"parm0"=>"",
"parm1"=>"",
"parm2"=>"",
"parm3"=>"",
"action"=>"add",
"lib_action"=>"Ajouter");
$this->displayForm($paramatres);
}
public function displayUpdate($id){
$this->page .= "<h3>Vous êtes sur la page de modification d'un utilisateur</h3>";
$paramatres = array(
"readonly"=>"",
"parm0"=>$id['id_user'],
"parm1"=>$id['Nom'],
"parm2"=>$id['Prenom'],
"parm3"=>$id['id_services'],
"action"=>"update",
"lib_action"=>"Modifier");
$this->displayForm($paramatres);
}
public function displayDelete($id){
$this->page .= "<h3>Vous êtes sur la page de suppression d'un utilisateur</h3>";
$paramatres = array(
"readonly"=>"readonly",
"parm0"=>$id['id_user'],
"parm1"=>$id['Nom'],
"parm2"=>$id['Prenom'],
"parm3"=>$id['id_services'],
"action"=>"delete",
"lib_action"=>"Supprimer");
$this->displayForm($paramatres);
}
private function displayForm($paramatres){
$this->page .= "<h3>Formulaire</h3>";
$this->page .= $this->searchPHP('userForm');
$this->page = str_replace("{readonly}", $paramatres["readonly"], $this->page);
$this->page = str_replace("{parm0}", $paramatres["parm0"], $this->page);
$this->page = str_replace("{parm1}", $paramatres["parm1"], $this->page);
$this->page = str_replace("{parm2}", $paramatres["parm2"], $this->page);
$this->page = str_replace("{parm3}", $paramatres["parm3"], $this->page);
$this->page = str_replace("{action}", $paramatres["action"], $this->page);
$this->page = str_replace("{lib_action}", $paramatres["lib_action"], $this->page);
$this->display();
}
public function display(){
$this->page .= $this->searchHTML('footer');
echo $this->page;
}
private function searchHTML($filename){
$content = file_get_contents('../MVC/view/html/'.$filename.'.html');
return $content;
}
private function searchPHP($filePHP){
$content = file_get_contents('../MVC/view/html/'.$filePHP.'.php');
return $content;
}
}
?>
-----