Hello I have a problHello I have a problem to display the results of my request in cakephp here is the request:em to display the results of my request in cakephp here is the request:
$connection = ConnectionManager::get(‘default’);
$marches = $connection->execute('SELECT COUNT(*) AS nombre,
num_contrat,
libelle_marche,
date_debut_marche,
date_fin_marche,
SUM(montant_cible),
SUM(montant_commande),
SUM(montant_receptionne)
FROM marches
GROUP BY libelle_marche
')->fetchAll(‘assoc’);
in my controller
public function planning()
{
$marches = $this->Marches->getMarche();
foreach($marches as $marche)
debug($marche->num_contrat);
die(‘hi’);
}
here is the message I have :
null
[ Notice (8)](javascript:void(0);): Trying to get property of non-object [ APP/Controller/MarchesController.php , line 39 ]
how to display the result in my view for example I would like to display the value of num_contrat, nombre …
thanks for your help
Ok line 39 represents : debug($marche->num_contrat.
to make it simple in my controller I have a function planning:
public function planning()
{
$connection = ConnectionManager::get(‘default’);
$marches = $connection->execute('SELECT COUNT(*) AS nombre,
num_contrat,
libelle_marche,
date_debut_marche,
date_fin_marche,
SUM(montant_cible),
SUM(montant_commande),
SUM(montant_receptionne)
FROM marches
GROUP BY libelle_marche
')->fetchAll(‘assoc’);
foreach($marches as $marche)
debug($marche);
die(‘hi’);
}
when I debug ($marche), I can see the results I want : /src/Controller/MarchesController.php (line 39 )
The results show that you have an array of results, not an object. Just like the error message would indicate. As such, you’d need to reference the value you’re looking for as $marche['num_contrat'].