Join while with for to fill in html table for working hours

0

I need to create a pdf with the record of a teacher's day. I have the table Schedules with (id, idTeacher, Day, HoraIni, HoraFin, Fecharegis) Being the Dia - > 1 = Monday, 2 = Tuesday, 3 = Wednesday ...) This is the code that I have to generate the pdf, but it only shows 1 day of the week, the problem is that if the teacher has two days, it only shows the day latest. As I would have to join the while with the for to show the 31 days and fill in only the days of the week that the teacher has. Thank you very much in advance !!

while ($myhorario = $Horaprofe->fetch_array(MYSQLI_ASSOC)) {
    $fechacalc=$myhorario['Dia'];
    $fecha=($fechacalc-$primerdia)+1;
    $fecha1 = $fecha + 7;
    $fecha2 = $fecha1 + 7;
    $fecha3 = $fecha2 + 7;
    $fecha4 = $fecha3 + 7;
    if($myhorario['HoraIni'] < '15:00' ){
    $hmi1=$myhorario['HoraIni'];
    $hmf1=$myhorario['HoraFin'];
    }else{
    $hti1=$myhorario['HoraIni'];
    $htf1=$myhorario['HoraFin'];    
    }}

for ($i = 1; $i <= 31; $i++) {

if($i==$fecha){
$html.='<tr>
<td width="60">'.$i.'</td>
<td width="100">'.$hmi1.'</td>
<td width="100">'.$hmf1.'</td>
<td bgcolor="#cccccc" width="5">&nbsp;</td>
<td width="100">'.$hti1.'</td>
<td width="100">'.$htf1.'</td>
<td width="140">&nbsp;'.$suma1.'</td>
<td width="150">&nbsp;</td>
</tr>';
}elseif($i==$fecha1){
$html.='<tr>
<td width="60">'.$i.'</td>
<td width="100">'.$hmi1.'</td>
<td width="100">'.$hmf1.'</td>
<td bgcolor="#cccccc" width="5">&nbsp;</td>
<td width="100">'.$hti1.'</td>
<td width="100">'.$htf1.'</td>
<td width="140">&nbsp;'.$suma1.'</td>
<td width="150">&nbsp;</td>
</tr>';
}elseif($i==$fecha2){
$html.='<tr>
<td width="60">'.$i.'</td>
<td width="100">'.$hmi1.'</td>
<td width="100">'.$hmf1.'</td>
<td bgcolor="#cccccc" width="5">&nbsp;</td>
<td width="100">'.$hti1.'</td>
<td width="100">'.$htf1.'</td>
<td width="140">&nbsp;'.$suma1.'</td>
<td width="150">&nbsp;</td>
</tr>';
}elseif($i==$fecha3){
$html.='<tr>
<td width="60">'.$i.'</td>
<td width="100">'.$hmi1.'</td>
<td width="100">'.$hmf1.'</td>
<td bgcolor="#cccccc" width="5">&nbsp;</td>
<td width="100">'.$hti1.'</td>
<td width="100">'.$htf1.'</td>
<td width="140">&nbsp;'.$suma1.'</td>
<td width="150">&nbsp;</td>
</tr>';
}elseif($i==$fecha4){
$html.='<tr>
<td width="60">'.$i.'</td>
<td width="100">'.$hmi1.'</td>
<td width="100">'.$hmf1.'</td>
<td bgcolor="#cccccc" width="5">&nbsp;</td>
<td width="100">'.$hti1.'</td>
<td width="100">'.$htf1.'</td>
<td width="140">&nbsp;'.$suma1.'</td>
<td width="150">&nbsp;</td>
</tr>';
}else{
$html.='<tr>
<td width="60">'.$i.'</td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td bgcolor="#cccccc" width="5">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="140">&nbsp;</td>
<td width="150">&nbsp;</td>
</tr>';
    
asked by Fernando Diez 06.03.2018 в 16:36
source

1 answer

1

I leave here as I have solved it in case someone might be interested. Thanks !!

foreach($arr as $row){ 

$horas=$row[2].' a '.$row[3];
$colorprofe=$row[4];

	if($horas<>$ultimo){
			
							$ultimo=$horas;
        					echo "<tr>";
            				echo "<td>" . $horas ."</td>";  
            				$ultitd=0; 
            				$diaant=1; 
            				$sumando=0; 
	}

			
    for($z=$diaant+$sumando; $z<=5; $z++){
           
            if($row[1]>$z)	{
            
           	   /* if ($row[1]<>$diaant){ */
            		echo "<td></td>";
  			 /* 	} */
  							}
  	}						
  								
  	if($row[1]<>$ultitd){echo "<td>";}			
  	echo "<button style='background: #".$colorprofe."' class='btn btn-default' data-toggle='modal'>" . $row[0] . "</button>";	
 	 
 	 $ultitd=$row[1];
 	 $diaant=$row[1];
 	 $sumando=1;
 	
 	 

}
    
answered by 01.06.2018 в 11:18