-1
Hi, I have another little 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 within the classes, for that, I know I need to use the command (SUM) within 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 so do a package control for example, where each student can have only one 8-hour package, each time that the student participates in the class, will add these values and decrease within my package table, as I do this working with PHP time duration?
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:
In this table, the duration of each class I managed to do normally, is returning everything right in the database, My problem is to take the data of this field (Duration) put in a variable and subtract within the field (times_rest) of the number id 22 in the table packages, since each package will only have one student
I couldn’t understand! Can’t subtract time values?
– Adell
If I understand correctly, your error happens only in PHP. In the database is working correctly. That’s it?
– jlHertel
There’s no mistake, I can’t make it
– William De Paula
I want to sum up everything you have within the field (duration) of the Wizard table and subtract within the field (given times) in the PHP table
– William De Paula
Example: Student José, such ID 3 attended class 2 for 1 hour and 20 minutes and class 3 for 1 hour and 32 minutes, the same student has the number 22 package he bought with an 8-hour limit, I just want the system to add up the hours assisted and subtract in the value of hours given within the packets table, then in the packet table, it has 8 hours of class limit and 0 hours until the moment of hours assisted, I want inside the field to show the value of 2 hours and 52 minutes (02:52) within the field (times_given) of the table packages
– William De Paula