PHP Grouping Question

Shuxclams

Diamond Member
Oct 10, 1999
9,286
15
81
I am trying to take this SQL:
SELECT transaction_id, username, service_area, ws_device_time, time_in_store, end_date, comments, excusable, regional_manager, rm_comments
FROM S3J_DA
WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= end_date AND excusable='N'
GROUP BY regional_manager, username
ORDER BY regional_manager, end_date


and then group the records by 'regional_manager'. I am wondering if its a DO..WHILE, WHILE, FOREACH or FOR.


The data should go something like this

regional_manager

transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments

regional_manager

transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments

regional_manager

transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments

regional_manager

transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments
transaction_id | username | service_area | ws_device_time | time_in_store | end_date | comments | excusable | rm_comments


Any suggestions?






SHUX
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
the data coming back from the query already looks like it's in the right order. i would probably just use a while loop and keep track of when the regional manager changes from one row to the next.
 

Shuxclams

Diamond Member
Oct 10, 1999
9,286
15
81
I am trying to figure out how to 'break' on each regional_manager' name change... this isnt working.

while ($rec = $db->fetchRow($result,DB_FETCHMODE_ASSOC)) {
echo "<h1> Time Variance Exceptions for: ".$rec[regional_manager]."\n </h1>";
}





SHUX