Jump to content

trying to add integers then convert to time


matthewst

Recommended Posts

A table in my database has a field named table_id.

For each "real" table (not mysql table) a certain amount of work is being done.

The time it takes for verious tasks at the tables to be compleated is being tracked in a field called time.

I can extract the times from each table to a page but I still need to add the total time for all tasks at each "real" table.

 

Example DB:

 

table_id    time

  1          57283

  1          6954

  2          6882495

  2          985146

  3          822469658

  3          5867

 

 

 

Example Page Output:

 

          Total Table Time

              57283

              6954

 

What I Need:

 

          Total Table Time

          Table 1  64237          17.84 hours

          Table 2  7867641      2185.46 hours

          Table 3  822475525  228465.42 hours

 

 

Here is what I have so far(I threw an actual table id in there for simplicity during testing): Any Ideas?

<?php
include('user_check.php');
include('db_con.php');
?>

<html>
<head>
<title>Reports</title>
</head>
<body bgcolor="white">
<font face="Verdana, Arial, Helvetica, sans-serif">

<?php
$query="SELECT time FROM job_log WHERE table_id=100391";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Total Table Time</center></b><br><br>";
$i=0;
while ($i < $num) 
{$time=mysql_result($result,$i,"time"); echo "<center>$time<br></center>"; $i++;}		
?> 

</body>
</html>

try

<?php
$sql = "SELECT table_id, SUM(time) as secs, SUM(time/3600) as hrs 
         FROM mytablename 
         GROUP BY table_id";
$res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
while (list($id, $secs, $hrs) = mysql_fetch_row($res)) {
    printf ('%d : %d : %10.2f hours<br>', $id, $secs, $hrs); 
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.