Jump to content

[SOLVED] SUM() problem


savagenoob

Recommended Posts

I want to calculate the sum of rows that fall between 2 dates but its calculating the total of all the rows no matter what dates I select. Here is my code...

<?php
$fquery="SELECT SUM(MinutesClock) FROM timeclock WHERE Employee = '$employee' AND Clock = 'Out' AND Time BETWEEN '$date4' AND '$date3' ";
		$fresult = mysql_query($fquery);
?>

doing an echo on $fquery shows....

"SELECT SUM(MinutesClock) FROM timeclock WHERE Employee = '4' AND Clock = 'Out' AND Time BETWEEN '2009-02-01 00:00:01' AND '2009-03-30 23:59:59'  Total Time Worked: 106 Hours 17 Minutes"

But it shouldnt be 106 hours...it says that no matter what.

Link to comment
https://forums.phpfreaks.com/topic/151864-solved-sum-problem/
Share on other sites

First of all, let's tell MySQL that "Time" isn't a keyword but in fact a fieldname:

$fquery="SELECT SUM(MinutesClock) FROM timeclock WHERE Employee = '$employee' AND Clock = 'Out' AND `Time` BETWEEN '$date4' AND '$date3' ";

 

If you can, work out how many minutes you should be getting back.

Link to comment
https://forums.phpfreaks.com/topic/151864-solved-sum-problem/#findComment-797585
Share on other sites

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.