Demande d'aide sur un type bool
J'essaye de retourner la liste des ateliers dans un programme de séminaire en ligne cela marche tout s'affiche mais j'ai une erreur de type bool
Merci de votre aide
Notice: Trying to access array offset on value of type bool in /home/apache/wseminaire/www/model/ModelParticipant.php on line 51
Merci de votre aide
Notice: Trying to access array offset on value of type bool in /home/apache/wseminaire/www/model/ModelParticipant.php on line 51
<?php
include_once('src/db/connect.php');
class ModelParticipant {
private $connect;
public function __construct(){
// Récupération de la connexion à la bdd
$cnt = new connect;
$this->connect = $cnt->setConnection();
}
public function read(){
// Récupération des données événements
$info = array();
$nbr = array();
$req2 = $this->connect->query('SELECT id, name_ev, date_ev FROM event ORDER BY date_ev DESC');
$res = $this->connect->query('SELECT id, name_ev, date_ev FROM event ORDER BY date_ev DESC');
while ($data2 = $req2->fetch()) {
$id = $data2['id'];
// Réucpèrer le nombre de participants
$req3 = $this->connect->prepare('SELECT COUNT(id) AS nbr FROM participant WHERE id_event=:value');
$req3->bindParam(':value', $id, PDO::PARAM_INT);
$req3->execute();
array_push($nbr, $req3->fetch());
$req3->closeCursor();
}
$return = array("res" => $res, "info" => $info, "nbr" => $nbr);
return $return;
}
public function readDetail($id) {
$req = $this->connect->prepare('SELECT id, id_event, name, lastname, fonction, tel, mail, particip, dej, din, ateliers FROM participant WHERE id_event=:value');
$req->bindParam(':value', $id, PDO::PARAM_INT);
$req->execute();
$req1 = $this->connect->prepare('SELECT ateliers FROM participant WHERE id_event=:value');
$req1->bindParam(':value', $id, PDO::PARAM_INT);
$req1->execute();
$atelier = array();
$i = 0;
while ($data = $req1->fetch()){
$at = explode(',', $data['ateliers']);
$atelier[$i] = "";
foreach ($at as $key) {
$req2 = $this->connect->prepare('SELECT name_atelier FROM atelier where id=:value');
$req2->bindParam(':value', $key, PDO::PARAM_INT);
$req2->execute();
$nameAt = $req2->fetch();
$atelier[$i] .= $nameAt['name_atelier']."<br />";
}
$i++;
}
$res = $req;
return array("1" => $res, "2" => $atelier);
}
2 réponses
-
Contributeurbonjour,
il me semble que tu négliges de vérifier si la requête a bien fonctionné.-
-
-
@yg_beTu peux pas me corriger dans le code je suis débutant ?
-
Contributeur@david76-21Tu vas rester débutant si tu n'apprends pas.
-
@yg_beJ'ai essayé cela $id = !empty($data['id']) ? $data['id'] : NULL ;
mais le résultat ne s'affiche pas
-