The array below is a sample of data returned from a MySQL query for all training records that are due within X interval (1 week, 1 month, etc.).
array [
0 => [
'company_id' => '10',
'date' => '2016-11-11'
'company' => ['name' => 'Company 1'],
'user' => ['first_name' => 'John', 'last_name' => 'Doe'],
'course' => ['name' => 'Course 1'],
'department' => ['name' => 'Dep 1'],
],
1 => [
'company_id' => '11',
'date' => '2016-11-30',
'company' => ['name' => 'Company 2'],
'user' => ['first_name' => 'Mark', 'last_name' => 'Smith'],
'course' => ['name' => 'Course 1'],
'department' => ['name' => 'Dep 1'],
],
2 => [
'company_id' => '11',
'date' => '2016-12-07',
'company' => ['name' => 'Company 2'],
'user' => ['first_name' => 'Mark', 'last_name' => 'Smith'],
'course' => ['name' => 'Course 2'],
'department' => ['name' => 'Dep 1'],
]
What I'm looking to do is select all records for each company and send a single email to the company manager containing the details of all training records for that company.
What would be the best way to do this?
What I was thinking was to create a new array containing just the company id's and then loop through that array and do an array_search on the original array for all records for that company.
Am I on the right track or am I over complicating things?
I can work out the sending of the emails myself... I just need to get the info into an array I can work with.
Something like this:
$records = [
'company_id' => '10'
'training_details' => [
0 => [
'user' => 'John Doe',
'course' => 'Course 1',
'department' => 'Dep 1',
]
],
'company_id' => '11'
'training_details' => [
0 => [
'user' => 'Mark Smith',
'course' => 'Course 1',
'department' => 'Dep 1',
'date' => '2016-11-30',
],
1 => [
'user' => 'Mark Smith',
'course' => 'Course 2',
'department' => 'Dep 1',
'date' => '2016-12-07',
],
],
];