Jeg er helt lost lige nu.
Min DB
- CREATE TABLE IF NOT EXISTS `times` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `fra` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `til` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
-
- --
- -- Data dump for tabellen `times`
- --
-
- INSERT INTO `times` (`id`, `fra`, `til`) VALUES
- (1, '2012-01-23 12:15:00', '2012-01-23 19:15:00'),
- (2, '2012-01-16 16:15:00', '2012-01-19 19:15:00');
Min index.php
- <?php
- $host = "localhost";
- $user = "root";
- $pass = "";
- $db = "work";
-
- $con = mysql_connect($host, $user, $pass) or die(mysql_error());
- mysql_select_db($db, $con) or die(mysql_error());
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
- <html>
- <head>
- <title>Work Time</title>
- </head>
- <body>
- <?php
- $query = mysql_query("SELECT SEC_TO_TIME(SUM(TO_SECONDS(TIME_DIFF(fra,til)))) FROM times WHERE fra >= '2012-01-01 00:00:00' AND til <= '2012-01-31 23:59:00'");
-
- $row = mysql_fetch_row($query)
- echo $row[0];
- ?>
- </body>
- </html>