0
What I intend to do is schedule times and dates on front-end according to the records of a table, but with the code I have I can only mark the first row of the table. How to go through the entire table by marking all the corresponding dates?
I had some success with another while
in place of mysqli_fetch_assoc()
using mysqli_fetch_array()
but it repeats the number of rows in the table, multiplying the hours of the front-end. Follows my code:
<div class="row">
<?
for ($i=0; $i < 12; $i++) {
$justDay=date('Y-m-d',strtotime("+$i days"));
$days=formatDt(date('Y-m-d',strtotime("+$i days")));
$dweek= strftime('%A', strtotime("+$i days, today"));
?>
<div class="col-md-1 bord-head-table text-center">
<span class="text-primary"><?= $days;?><br><!--linha exbe semana--></span><br>
<span class="text-white fontweek"><?=utf8_encode($dweek); ?></span>
<hr class="border-lime">
<!-- chama tabela horas-->
<? $sql = "SELECT * from horas";
$qr=mysqli_query($conexao,$sql);
$it=0;
while ($ft=mysqli_fetch_array($qr)) {
$it++;
$sqlAula = "SELECT * from monta_aula";
$qrAula=mysqli_query($conexao,$sqlAula);
$ftAula=mysqli_fetch_assoc($qrAula);
$hrAula=$ftAula['hora_inicio_aula'];
/* compara hora e data da tabela aula com a hora e data do front end e contorna o horário correspondente ao cadastrado no banco, na tabela aula*/
if ($hrAula == $ft['hora'] and $justDay == $ftAula['dia_aula']) {
$hc="border-class";
} else{
$hc="text-green-d";
}
?>
<div class="bord-hours">
<a href="#" class="<?=$hc;?>">
<?=$ft['hora'];?>
</a><br>
</div>
<? }//while ?>
</div>
<!--col md 1 - representa cada coluna, com data, dia da semana e horários (de 08:00:00 às 21:00:00)-->
<? }//for ?>
</div>
<!--row-->
Table to go:
Table Hours:
Front End:
Your code is a little confusing for me. you are making two selects, one of hours I have no way of knowing what the data is from that tabale, and the other looping within the while. I think you would solve all this compared to a single select. And assembling this schedule table at the same time that already makes the comparison with the returned data. It would have to be analyzed with more time and restructure its code. But about the
mysqli_fetch_array($qr)
, have tried to use like this:mysqli_fetch_array($qr, MYSQLI_ASSOC)
. I believe that MYSQLI_ASSOC would avoid repetition.– Fernando VR