savagenoob Posted March 31, 2009 Share Posted March 31, 2009 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 More sharing options...
Yesideez Posted March 31, 2009 Share Posted March 31, 2009 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 More sharing options...
savagenoob Posted March 31, 2009 Author Share Posted March 31, 2009 The example isnt showing... The minutes I should be getting differs based off of dates selected so it depends on whats selected. Link to comment https://forums.phpfreaks.com/topic/151864-solved-sum-problem/#findComment-797697 Share on other sites More sharing options...
fenway Posted April 1, 2009 Share Posted April 1, 2009 Post your solution, please. Link to comment https://forums.phpfreaks.com/topic/151864-solved-sum-problem/#findComment-798584 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.