Afficher une liste de participants

Résolu/Fermé
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 - Modifié le 1 oct. 2021 à 07:07
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 - 1 oct. 2021 à 11:56
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.

Voici le code 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 ce code pour afficher en modal la liste de participant:
<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>

A voir également:

4 réponses

chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1
1 oct. 2021 à 08:13
Et comment réduire le nombre de place d'une formation quand une personne participe à la formation en question? (j'ai oublié de mentionner dans le sujet)
0
jordane45 Messages postés 38381 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 15 janvier 2025 4 727
1 oct. 2021 à 11:03
Bonjour,


J'aimerai afficher la liste de participant qui ont participé à la formation qu'ils ont sélectionné

déjà... comment tu sais sur quelle formation tu te trouves ?
quel est le code qui déclenche l'ouverture de la modal ?
La charges tu en ajax ?

Et puis, niveau code, il te faudra une fonction du genre
public function getAllParticipantByFormation($id_formation){
    $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
    WHERE F.formaID = '$id_formation'
    ORDER BY nomParticipant ASC";
    if($sql = $this->conn->query($query)) {
        while($row = mysqli_fetch_assoc($sql)) {
            $data[] = $row;
        }
    }
    return $data;
}    

et apeller cette fonction pour récupérer que les participants à cette formation
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1
1 oct. 2021 à 11:42
c'est au niveau de ce code qu'on appelle le modal

 <div class="modal fade" id="staticBackdropParticipant" data-bs-backdrop="static" >...</div>


Et j'ai lié avec l'id de la balise html pour ouvrir la formation qui correspond :
<a href="#staticBackdropParticipant">
                        <button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#staticBackdropParticipant">
                        Afficher
                        </button>
                    </a>
0
jordane45 Messages postés 38381 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 15 janvier 2025 4 727
1 oct. 2021 à 11:54
Tu veux dire que tu as créé une modal par formation ?
Donc dans la même page tu as x dois le code html de la modal ????
beurk !!

Normalement, histoire que ça soit propre et que ça ne surcharges pas trop ta page ( car plus tu mets de html dedans.. plus elle sera lourde à afficher ...) et pour éviter que n'importe qui puisse aller voir qui participe à telle ou telle formation juste en regardant le code source de la page .... il ne faut avoir qu'une seule modal
Modal que tu rempliras, grace à du javascript et de l'ajax ... en fonction de la formation cliquée ...

Si tu ne sais pas comment faire de l'ajax .. forme toi dessus...
ça serait trop long de te l'expliquer via des messages sur le forum... trouves des formations/tutos sur le net.
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1
1 oct. 2021 à 11:56
Okay je ferai ça, merci beaucoup
0