Hello, I have another problem and I need someone's help. The system I'm doing is for a school and I need my system to calculate the duration that each student had in class, so I know I need to use the (SUM) command inside my select, more and then? The final result that I need is to show in an echo all the hours that this student had studying and thus to do a control of packages for example, where each student can only have a package of 8 hours, each time the student participates in class, will sum these values and decrease within my table package, how do I do this working with time duration in PHP?
All I have is this code:
<?php
$pesquisa_horas_dadas = mysql_query("SELECT SUM(horas_dadas) FROM pacotes");
while($sum = mysql_fetch_array($pesquisa_horas_dadas)){
$soma_horas_dadas = $sum['horas_dadas'];
}
echo $soma_horas_dadas; echo"</br>";
$seleciona_duracao = mysql_query("SELECT SUM(Duracao) FROM Assiste");
$resultset = mysql_query('SELECT SUM(Duracao) as Duracao FROM Assiste');
$linha= mysql_fetch_assoc($resultset);
$soma = $linha['Duracao'];
echo $soma; echo"</br>";
$soma01 = "01:23";
$totalHora = $soma / 3600;
function converterHora($soma){
$hora = sprintf("%02s",floor($soma / (60*60)));
$minuto = ($soma01 % (60*60));
$soma = sprintf("%02s",floor ($soma / 60 ));
$soma = ($soma % 60);
$hora_minuto = $hora.":".$minuto;
return $hora_minuto;
}
$hora = converterHora($segundosTotal);
echo $hora;
?>
MYSQL example:
Inthistable,thedurationofeachclassIwasabletodonormally,isreturningeverythingcorrectinthedatabase,Myproblemistotakethedataofthisfield(Duration)putinavariableandsubtractinsidethefield(hours_rest)ofthenumber22inthepackettable,sinceeachpacketwillonlyhaveonestudent