StanLytle Posted March 19, 2009 Share Posted March 19, 2009 No matter what I try, I can't get the table that is output to be limited by the cut off time (ie: last 10 days). I finally got rid of all the mySQL errors, but now I'm stumped. Any suggestions appreciated. $CutOffTime = strtotime('-14400 minutes', $CurrentTime); $query = "SELECT UserID, Name, COUNT(UserID) FROM Rejections WHERE (Date > '$CutOffTime') GROUP BY UserID ORDER BY UserID"; $result = mysql_query($query) or die(mysql_error()); while(list($id, $name, $ct) = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>$id</td>"; echo "<td>$name</td>"; echo "<td>$ct</td>"; echo "</tr>"; } Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/ Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 what field type is is the Date column? Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788414 Share on other sites More sharing options...
StanLytle Posted March 19, 2009 Author Share Posted March 19, 2009 The date column is int(20). Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788583 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 um, the only other thing i see wrong is i think the GROUP BY needs the name in it to: $query = "SELECT UserID, Name, COUNT(UserID) FROM Rejections WHERE (Date > '$CutOffTime') GROUP BY UserID, Name ORDER BY UserID"; is it outputting anything at all? what is it showing and what do you expect? if you echo the value of $query just before executing it, what does it say? Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788611 Share on other sites More sharing options...
StanLytle Posted March 19, 2009 Author Share Posted March 19, 2009 The table outputs, the structure is fine, it counts and groups correctly, but it will not output only the most recent days as set by $CutOffTime. It outputs the entire table, from day 1. I want to limit the output to only whatever number of days that I specify. Stan Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788638 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 before the query, if you echo the values of $CurrentTime and $CutOffTime, what are they? Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788645 Share on other sites More sharing options...
StanLytle Posted March 19, 2009 Author Share Posted March 19, 2009 I think that you are onto something. $CutOffTime is -864000, but $CurrentTime is blank (no numbers, not even 0). So $CurrentTime must not have any vlaue. How do I get the current time into $CurrentTime? Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788692 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 if all you care about it relative to now, just drop that variable all together: $CutOffTime = strtotime('-14400 minutes'); p.s. - you should be able to do days instead of minutes too: $CutOffTime = strtotime('-10 days'); Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788697 Share on other sites More sharing options...
kickstart Posted March 19, 2009 Share Posted March 19, 2009 Hi Can't you just leave off $CurrentTime from strtotime? All the best Keith Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788698 Share on other sites More sharing options...
StanLytle Posted March 19, 2009 Author Share Posted March 19, 2009 I went with $CutOffTime = strtotime('-10 days'), and it worked just as I wanted it to. Thank you for all of your help. Stan Link to comment https://forums.phpfreaks.com/topic/150130-solved-limiting-table-output-to-recent-x-number-of-days/#findComment-788717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.