I want to get a list of all tasks grouped by task and all of the users assigned to it.
Something like this:
Task id: 1, name: do dishes, users: bob, liam.
I only got to print a task twice if there were 2 users assigned to it.
The CodeIgniter query returns a 2d array via result() with 2 rows:
- 1 for the task with the user bob and
- 1 for the same task with the user liam.
array{
array{
task_id = "1",
name = "do dishes",
user = "bob"
}
array{
task_id = "1",
name = "do dishes",
user = "liam"
}
array{
task_id = "2",
name = "vacuum",
user = "liam"
}
array{
task_id = "3",
name = "Take out thrash",
user = "liam"
}
array{
task_id = "3",
name = "Take out thrash",
user = "bob"
}
}
What I want to get is a result with 1 row containing the task and within that row I want an array with each name of the users assigned to it.
array{
array{
task_id = "1",
name = "do dishes",
user = array( "bob", "liam" )
}
array{
task_id = "2",
name = "vacuum",
user = array( "liam" )
}
array{
task_id = "3",
name = "Take out thrash",
user = array( "liam", "bob" )
}
}
Is there any way to achieve this within CI and/or MySQL?