Re: PHP querying mysql db for data limited to the last month
| From: | Per Jessen | Date: | Tue, 05 Aug 2008 08:47:57 +0000 |
| Subject: | Re: PHP querying mysql db for data limited to the last month | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-277700@lists.php.net to get a copy of this message | ||
Vinny Gullotta wrote:
> So I have this code I'm working with (pasted below) that queries a
> mysql db table called timetracking. The goal of the page is to search
> the db for all data based on a certain engineer, sorted by product and
> it takes pre-defined values based on actions performed, sums them
> based on product and display's the percentage of time an engineer has
> spent on each product. Everything works great except I need to limit
> the results to the last months data only, but everything I try seems
> to just break it. Can anyone push me in the right direction a little?
I can't see a timestamp field in your code, but I'm assuming you've got
one?
SELECT *,SUM(timespent) FROM timetracking
WHERE engineer=<engineer> AND
month(timestamp)=month(date_sub(now(),interval 1 month))
GROUP BY product;
/Per Jessen, Zürich