Partage
  • Partager sur Facebook
  • Partager sur Twitter

Afficher une liste de participants

Php, HTML

    1 octobre 2021 à 8:09:09

    Bonjour, je commence php et j'ai un projet portant sur la création de formation/cours.

    Intro : On peut créer un programme/cours et à partir de ce programme, nous pouvons organiser une formation/cours.

    Lors de cette création de formation, nous pouvons participer en remplissant un formulaire et cela.
    Le problème ici c'est que j'aimerai afficher la liste de participant qui ont participé à la formation qu'ils ont sélectionné mais dans mon cas, il affiche juste tous les participants existants. Et comment réduire le nombre de place d'une formation quand une personne participe à la formation en question?

    Voici le code de participant.php : 

    function participant(){
        if(isset($_POST['nomParticipant']) && isset($_POST['prenomParticipant']) && isset($_POST['fonctionParticipant']) && isset($_POST['serviceParticipant'])) {
            $nomParticipant = $_POST['nomParticipant'];
            $prenomParticipant = $_POST['prenomParticipant'];
            $fonctionParticipant = $_POST['fonctionParticipant'];
            $serviceParticipant = $_POST['serviceParticipant'];
    
            if(empty($nomParticipant)){
                header("Location: index_admin.php?error=Nom du participant requis");
                exit();
            } else {
                $query = "INSERT INTO participant (nomParticipant, prenomParticipant, fonctionParticipant, serviceParticipant) VALUES ('$nomParticipant', '$prenomParticipant', '$fonctionParticipant', '$serviceParticipant')";
                if($sql = $this->conn->query($query)) {
    
                    echo "<div class='card w-25' style='padding:20px;color: #FFBC42; margin:auto;'>
                    <h5 style='text-align:center'>
                    <i class='fas fa-check-circle'></i>  <b><q> ".$_POST['nomParticipant']." ".$_POST['prenomParticipant']." </q> 
                    a bien été enregistré pour cette formation</b></h5>
                    <a href='../admin/index_admin.php' style='color:grey;text-align:center'>Retour vers la page d'accueil</a>
                    </div>";
                    exit();
                } else {
                    header("Location:index_admin.php");
                    exit();
                }
            }
        }
        
    }
    
    public function getAllParticipant(){
        $data = null;
        $query = "SELECT P.participantID
        ,P.programmeChoisi
        ,P.nomParticipant
        ,P.prenomParticipant
        ,P.fonctionParticipant
        ,P.serviceParticipant
        ,F.programme 
        FROM participant P
        LEFT JOIN forma F  ON P.programmeChoisi = F.programme
        ORDER BY nomParticipant ASC";
        if($sql = $this->conn->query($query)) {
            while($row = mysqli_fetch_assoc($sql)) {
                $data[] = $row;
            }
        }
        return $data;
    }  

    Et le code pour afficher en modal les partipants :

    <td style="text-align:center;vertical-align:middle"><a href="#staticBackdropParticipant">
                        <button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#staticBackdropParticipant">
                        Afficher
                        </button>
     </td>
    
      <!-- Modal pour afficher les Participant -->
    <div class="modal fade" id="staticBackdropParticipant" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                                <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
                                    <div style="margin-top:120px;width:800px" class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title" id="staticBackdropLabel" style="color:rgb(40, 87, 216);"><b>Liste des Participants</b> </h5>
                                            <a href="#"><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></a>
                                        </div>
    
                                        <div class="modal-body">
                                            <table class="table table-bordered table-striped table-hover">
                                                <thead>
                                                    <tr style="color:white;background:#45509E;text-align:center">
                                                    <th scope="col">Nom</th>
                                                    <th scope="col">Prénom</th>
                                                    <th scope="col">Fonction</th>
                                                    <th scope="col">Service</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
    
                                                <?php if(!empty($rowsallParticipant)) {
                                                foreach($rowsallParticipant as $rowParticipant) {?> 
                                                    <tr>
                                                        <td><?php echo $rowParticipant['nomParticipant']?></td>
                                                        <td><?php echo $rowParticipant['prenomParticipant']?></td>
                                                        <td><?php echo $rowParticipant['fonctionParticipant']?></td>
                                                        <td><?php echo $rowParticipant['serviceParticipant']?></td>
                                                    </tr>
                                                    <?php }
                                                    }else {
                                                        exit();
                                                    }
                                                    ?>
                                                </tbody>
                                            </table>
                                        </div>
    
                                        <div class="modal-footer">
                                            <a href="#"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button></a>
                                        </div>
                                    </div>
                                </div>
                </div>




    -
    Edité par ChristianChanLong 1 octobre 2021 à 8:12:38

    • Partager sur Facebook
    • Partager sur Twitter
      1 octobre 2021 à 12:17:15

      Bonjour,

      Je dirai pour la liste qu'il te manque une clause permettant de discriminer la formation.

      Pour le nombre il te faut un compteur de places disponibles par formation et à chaque inscription tu fais moins 1 avant d'arriver à 0.

      A+

      • Partager sur Facebook
      • Partager sur Twitter
        1 octobre 2021 à 13:35:42

        Comment je pourrais procéder à la clause?
        • Partager sur Facebook
        • Partager sur Twitter
          1 octobre 2021 à 14:27:01

          Par exemple : une clause where dans ta requête qui identifie la formation par son id. Je ne connais pas ton schéma de base de données.

          A+

          • Partager sur Facebook
          • Partager sur Twitter
            4 octobre 2021 à 7:14:21

            Voici mon schema de bd:

            Et j'ai ajouté dans participant.php (où on affiche les participants et crée les participants) :

            public function getAllParticipantByFormation($formaid) {
                $data = null;
                $query = "SELECT P.participantID
                ,P.formaChoisi
                ,P.nomParticipant
                ,P.prenomParticipant
                ,P.fonctionParticipant
                ,P.serviceParticipant
                ,F.formaID 
                FROM participant P
                LEFT JOIN forma F  ON P.formaChoisi = F.formaID
                ORDER BY nomParticipant ASC
                WHERE formaID = " .$formaid;
                if($sql = $this->conn->query($query)) {
                    while($row = mysqli_fetch_assoc($sql)) {
                        $data[] = $row;
                    }
                }
                return $data;
            }   


            Et read.php pour afficher les participants ayant inscrit à la formation choisi: 

            <div class="container-fluid">
                        
            
                    <?php 
                    include '../model/creerForm.php';
                    include '../model/creerPogramme.php';
                    include '../model/participant.php';
                    $formaid = $_REQUEST['read'];
                    $model = new participant;
                    $row = $model->getAllParticipantByFormation($formaid); 
                    ?>
            
            <br><br><br>
            
            
            <div style="margin-bottom: 50px;margin-top:-70px">
                <a href="index_admin.php"><button class="btn btn-secondary">Retour</button> </a>
                <h2 style="color:rgb(40, 87, 216);text-align:center"><b>Liste de participants à la formation</b> </h2> <br>
            
                <table class="table table-bordered table-striped table-hover">
                    <thead>
                        <tr style="color:white;background:#45509E;text-align:center">
                        <th scope="col">Nom</th>
                        <th scope="col">Prénom</th>
                        <th scope="col">Fonction</th>
                        <th scope="col">Service</th>
                        </tr>
                    </thead>
                    <tbody>
            
                    <?php if(!empty($row)) {?> 
                        <tr>
                            <td><?php echo $row['nomParticipant']?></td>
                            <td><?php echo $row['prenomParticipant']?></td>
                            <td><?php echo $row['fonctionParticipant']?></td>
                            <td><?php echo $rowt['serviceParticipant']?></td>
                        </tr>
                        <?php }
                        else { ?>
                            <h3 style="text-align: center;">Aucun participants sur cette formation</h3>
                        <?php 
                        } 
                        ?>
                        
                    </tbody>
                </table>
            
            </div>



            • Partager sur Facebook
            • Partager sur Twitter
              11 octobre 2021 à 12:58:27

              Qui pourrait m'aider s'il vous plait? 😕
              • Partager sur Facebook
              • Partager sur Twitter

              Afficher une liste de participants

              × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
              × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
              • Editeur
              • Markdown