This topic is locked
[SOLVED]

 Limited display from a table

9/24/2014 12:25:10 PM
PHPRunner General questions
C
cyberslugg author

Hello,
I have a table that has "number of hours worked" and "year". The user add's a new record every year to this list showing the total number of hours worked in the last year.
I need to do 2 things
1 - I want to only display the last 5 years that have been entered (I have them listing in descending order now but is shows all history)
2 - I want to show a total for the last 5 years (** I have already used the totals to add a line showing the user's career total, now I just need to add the total for the most recent 5 years)
any help would be great.
Thanks

Sergey Kornilov admin 9/25/2014

Add WHERE clause to your query to limit data.

SELECT * from MyTable

WHERE DATE_SUB(CURDATE(),INTERVAL 5 YEAR) <= DateColumn


MyTable and DateColumn need to be replaced with the actual table and column name.

C
cyberslugg author 10/5/2014

Thanks, meant to mark this as solved. That worked great.