Hello, I am trying to bring in a table the grouping of all steps and item evaluation per year along with the average of the scores and weights.
I can only bring the last step and item p table, that is, it is not doing the grouping, although the error is pointing to another line (357 - marked in the code below).
Exemplification:
Table
step item score weight year area (area n is required)
A, item 1,2,4,2010
A, item 1,5,2,2010
A, item 1,3,2,2010
A, item 2,3,2,2010
A, item 2,3,2,2010
B, item 1,2,4,2010
B, item 1,5,2,2010
B, item 1,3,2,2011
And on the screen, I need you to show:
step, item, AVG score, Avg weight, total, year
A, item 1.3.3.5.3,17.49,2010
A, item 2,3,2,6,2010
B, item 1,5,4,2010
B, item 1,3,2,2011
Any doubt in the tables, you can ask. I tried to do it in a summarized way
The error is as follows:
(!) Fatal error: Can not use object of type stdClass as array in C: \ wamp64 \ www \ system line 357
Follow the code below:
<?php
$pdo = Conexao::getInstance();
$dados = $pdo->prepare("SELECT etapa, item_avaliacao,ano,AVG(pontuacao),AVG(peso) FROM item_avaliacao_pg GROUP BY etapa, item_avaliacao, ano");
$dados->execute();
if($dados->rowCount()>=1){
?>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Item Avaliação PG</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Etapa</th>
<th>Item avaliação</th>
<th>Nível satisfação</th>
<th>Pontuação(0-5)</th>
<th>Peso</th>
<th>Total</th>
<th>Ano</th>
</tr>
</thead>
<tbody>
<?php while($table = $dados->fetch(PDO::FETCH_OBJ)){
?>
<tr>
<?php
echo'<td>'.$table->etapa.'</td>';
echo'<td>'.$table->item_avaliacao.'</td>';
// echo'<td><img src="'.$table->nivel_satisfacao.'" height="42" width="42"></td>';
//echo'<td>'.$table->nivel_satisfacao.'</td>';
echo'<td>'.$table['AVG(pontuacao)'].'</td>'; //LINHA 357
echo'<td>'.$table['AVG(peso)'].'</td>';
echo'<td>'.$table['AVG(pontuacao)']*$table['AVG(peso)'].'</td>';
echo'<td>'.$table->ano.'</td>';
//Desativado
// echo '<td><a class="btn btn-app" href="editando-item-avaliacao.php?id='.$table->id_item_avaliacao_pg.'"><i class="fa fa-edit"></i>Editar</a></td>';
}
}
?>
</tr>
</tbody>
<tfoot>
<tr>
<th>Etapa</th>
<th>Item Avaliação</th>
<th>Nível Satisfação</th>
<th>Pontuação</th>
<th>Peso</th>
<th>Total</th>
<th>Ano</th>
Thank you!