Notice: Trying to access array offset on value of type bool in
Résolu
Bonjour,
Avec la nouvelle version de php mon application de séminaire en ligne rencontre des erreurs.
Notice: Trying to access array offset on value of type bool in /home/apache/wseminaire/www/model/ModelAdmin.php on line 23
Notice: Trying to access array offset on value of type bool in /home/apache/wseminaire/www/model/ModelAdmin.php on line 29
Notice: Trying to access array offset on value of type bool in /home/apache/wseminaire/www/model/ModelAdmin.php on line 30
Pouvez-vous m'aider ?
Je vous en remercie par avance
Avec la nouvelle version de php mon application de séminaire en ligne rencontre des erreurs.
Notice: Trying to access array offset on value of type bool in /home/apache/wseminaire/www/model/ModelAdmin.php on line 23
Notice: Trying to access array offset on value of type bool in /home/apache/wseminaire/www/model/ModelAdmin.php on line 29
Notice: Trying to access array offset on value of type bool in /home/apache/wseminaire/www/model/ModelAdmin.php on line 30
<?php
include_once('src/db/connect.php');
class Admin {
private $connect;
public function __construct(){
// Récupération de la connexion à la bdd
$cnt = new connect;
$this->connect = $cnt->setConnection();
}
public function calendar(){
// Récupération des données événement pour le calendrier
$req = $this->connect->query('SELECT id, name_ev, date_ev FROM event ORDER BY ID');
return $req;
}
public function nextEv(){
// Récupération des données du prochain événement
$req = $this->connect->query('SELECT id, name_ev, date_ev FROM event WHERE date_ev > CURRENT_DATE ORDER BY date_ev ASC LIMIT 1');
$data = $req->fetch();
$id = $data['id'];
$req2 = $this->connect->prepare("SELECT COUNT(id) as nbr_participant FROM participant WHERE id_event = :id AND particip = 'oui'");
$req2->bindParam(':id', $id, PDO::PARAM_INT);
$req2->execute();
$data2 = $req2->fetch();
$particip = $data2['nbr_participant'];
$nextEv = $data['name_ev'];
$dateEv = $data['date_ev'];
$res = ['dateEv' => $dateEv, 'nextEv' => $nextEv, 'particip' => $particip];
return $res;
}
Pouvez-vous m'aider ?
Je vous en remercie par avance
6 réponses
-
J'ai un autre problème sur une autre page de mon programme j'essaye la même méthode mais cela ne marche pas :
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); }-
ModérateurTu dis avoir essayé la même méthode ... mais je ne le vois pas dans le code que tu nous montres ....
En plus, découper ton code en petites fonctions serait sûrement plus facile pour ensuite le maintenir et le debugeur.
En grospublic function getParticipantsByIdEvent($id_event) { try { $sql = 'SELECT id, id_event, name, lastname, fonction, tel, mail, particip, dej, din, ateliers FROM participant WHERE id_event=:value'; $req = $this->connect->prepare($sql); $req->bindParam(':value', $id_event, PDO::PARAM_INT); $req->execute(); return $req->fetchAll(); // retourne le resultat sous forme d'array } catch (Exception $ex) { echo "Erreur :" . $e->getMessage(); exit; } } public function getAtelierById($id_atelier) { try { $req = $this->connect->prepare('SELECT name_atelier FROM atelier where id=:value'); $req->bindParam(':value', $id_atelier, PDO::PARAM_INT); $req->execute(); return $req->fetchColumn(); // retourne la première colonne d'une ligne de resultat sous forme d'array } catch (Exception $e) { echo "Erreur :" . $e->getMessage(); exit; } } public function readDetail($id) { $participants = $this->getParticipantsByIdEvent($id); $atelier = array(); if(!empty($participants)){ foreach($participants as $K=>$V){ $atelier[$K] = ""; $at = explode(',', $V['ateliers']); if(!empty($at)){ foreach ($at as $id_atelier){ $atelier[$K] .= $this->getAtelierById($id_atelier); } } } } return array("1" => $participants, "2" => $atelier); }
A noter que.. si au lieu de stocker les ateliers de tes participants dans un champ tu avais créé une table spécifique
tbl_ateliers_participants ( id_participant, id_atelier )
tu aurais, via une simple jointure, pu tout obtenir avec une seule requête SQL au lieu d'exécuter des requêtes dans des boucles ( ce qui est fortement déconseillé ...et source de lenteurs dans les programmes )
Encore faut-il que tu saches ce qu'est une jointure .. et comment concevoir correctement une base de données relationnelle...
PS: A l'avenir ... pour toute nouvelle question .. merci de créer une discussion spécifique sur le forum.
Celle ci étant considérée comme déjà résolue et fermée.
-