Hello,
I have a database which calculates of time. My PHP page works well with this request which uses group by but I would like to add a cell, at the bottom of the table with the total of the column HH:MM. I have at the moment no idea. Could you give me an idea ?. Thank you.
<?php
$liendb = mysql_connect($bddserver, $bddlogin, $bddpassword);
mysql_select_db ($bdd);
?>
<div class="note">
<p class="title">Note</p>
<p class="title">Cette page affiche la ventilation des heures par activité entre deux dates. La requête tient compte du type d'activité ou sous-catégorie.</p>
</div>
<div id = "recherche">
<form action="ventilation_categories.php" method="post">
<img src="calendrier.jpg" width="90" height="90" alt="Calendrier" title="Saisir deux dates" border="0" /> entre
<input name="somme_PA_1" value="<?php echo $somme_PA_1; ?>" size="10" id="f_date_c" /><button type="button" id="f_trigger_c">...</button>
et
<input name="somme_PA_2" value="<?php echo $somme_PA_2; ?>" size="10" id="f_date_d" /><button type="button" id="f_trigger_d">...</button>
<input type="submit" value="Valider">
</form>
</div>
<table id="result">
<tr>
<th>Activités</th>
<th>Minutes</th>
<th>Centièmes</th>
<th>HH:MM</th>
</tr>
<?php
if (isset($somme_PA_1));
if (isset($somme_PA_2));
{
$clause = " AND (gtd.date BETWEEN '$somme_PA_1' AND '$somme_PA_2') GROUP BY(activites) ";
}
$sql = "SELECT CONCAT(activite,' ', categorie) AS 'activites', SUM(duree) as 'min', ROUND(SUM(duree / 60), 2) as 'duree', SUM(duree) as 'minutes' FROM gtd, type WHERE gtd.id_type = type.id " . $clause;
$resultat = mysql_query ($sql);
while ($eleve = mysql_fetch_array ($resultat))
{
$activite = $eleve['activites'];
$min = $eleve['min'];
$duree = $eleve['duree'];
$minutes = str_pad ( floor ( $eleve[ 'minutes' ] / 60 ), 2, 0, STR_PAD_LEFT );
$minutes .= ':';
$minutes .= str_pad ( $eleve[ 'minutes' ] % 60, 2, 0, STR_PAD_LEFT );
echo "<tr>";
echo "<td>$activite</td>";
echo "<td>$min</td>";
echo "<td>$duree</td>";
echo "<td>$minutes</td>";
echo "<tr>";
}
echo "</table>";
// i tried this but it is the total of the database not the query...
$sql = "SELECT SUM(minutes) AS 'total' FROM gtd";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row['total'];
?>
A screenshot…
ImageShack® - Online Photo and Video Hosting