Hello, I'm trying to build a report page in php using data from the database but I'm not able to lay the data horizontally correctly.
The logic is as follows:
startingdate|enddate|stations(canbe1ormore)
Thissearchshouldreturntime,stationname,andstationvalue
Thenumberofrowsandcolumnswilldependonthesearchresult
Iwouldlikeittoshowasfollows:
SofarI'vedoneawhileshowingmethenamesofthestationshorizontally
$stm=$conexao->prepare("SELECT * FROM tb_estacoes where id_estacao in($estacoes)");
$stm->execute();
$count = $stm->rowCount();
while($re = $stm->fetchObject()){
echo '<td>'.$re->estacao.'</td>';
}
Now I need to complete the cells with the time and value data for each season. I tried doing using for:
$select = $conexao->prepare("SELECT a.*, b.id_estacao, b.estacao FROM tb_dados a, tb_estacoes b where a.id_estacao in($estacoes) AND a.dt_medicao BETWEEN '$dtinicio' AND '$dtfim' AND a.id_estacao = b.id_estacao");
$select->execute();
$i=0;
while($number = $select->fetchObject()){
echo "<td>" .$number->horario. "</td>";
for ($i = 0; $i >= $count; ++$i) {
echo "</tr><tr>";
$i = 0;
}
echo "<td>" .$number->valorEstacao. "</td>";
}
In this way it shows the data run (does not separate by station) then the values of 1 station, are distributed in all columns, what is wrong ..
I do not know if I have to do a select for each station, or work with arrays ..
If anyone has any idea how I can do this, I would appreciate it.