Jump to content

Sort And Group Data By Week.


sdbeach

Recommended Posts

I would like to query a database named 'data' and have it pull all information for a specific job by week and have it grouped by 'name'. My table is shown below.

 

id admin_hrs shop_hrs fab_hrs paint_hrs vacation_hrs control_hrs test_hrs engine_hrs hydraulic_hrs date active bid_hrs name lead job

 

I have used the below query to get the information that I want for all dates, but cannot figure out how to separate them by weeks. Below is the result for my query for all entries using the statement below....

 

$query = "SELECT job, date, name, SUM(test_hrs),SUM(fab_hrs),SUM(control_hrs),SUM(shop_hrs),SUM(paint_hrs),SUM(engine_hrs),SUM(hydraulic_hrs) FROM data WHERE job LIKE '%" . $job . "%'GROUP BY name";

 

NAME LABOR TOTALS CAIN CHARLES 1 CHANDLER JAMES 4 FRONCK WILLIAM 13 GEORGE SETH 5 GRAHAM JOHN 4.75 HIGGINS ERIC 4.5 THEIL ALEC 0.5 WILSON ALLEN 9.5

 

 

I would like it to have a column of "week number" like below...

Week NAME LABOR TOTALS 1 CAIN CHARLES 1 1 CHANDLER JAMES 3 2 CHANDLER JAMES 4 1 FRONCK WILLIAM 4 2 FRONCK WILLIAM 23 3 FRONCK WILLIAM 13

 

They would not pick a date, it would just see the date field and sort by the week. I have read documentation on the week() function but cannot get the desired results. I put the query in a while loop to get the records displayed.

 

Any help would be greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/268751-sort-and-group-data-by-week/
Share on other sites

Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read.

Also, posting an example of what you got from the failed query, plus what you expected from it, would go a long way in helping us helping you.

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.