1
I am trying to assemble a Mysql query with multiple joins, in this query has a column that may or may not come duplicated, I would like to put the duplicated rows by this column in an array, using the GROUP BY, query returns only one of the records. Follow the query:
ETID: The idea is to group the classes of a discipline by the day of the week.
'SELECT `l`.`lnkId`, `s`.`schWeekDay`, `d`.`dscType`, `d`.`dscName`, `s`.`schStartAt`, `r`.`rmName`
FROM '.DATABASE['name'].'.`tblschedule` `s`
INNER JOIN '.DATABASE['name'].'.`tblstudent` `st`
ON `st`.`stdCode` = :username
INNER JOIN '.DATABASE['name'].'.`tbllinks` `l`
ON `l`.`lnkUser` = `st`.`stdRegister`
INNER JOIN '.DATABASE['name'].'.`tbldiscipline` `d`
ON `d`.`dscCode` = `s`.`schDiscipline`
INNER JOIN '.DATABASE['name'].'.`tblroom` `r`
ON `r`.`rmId` = `s`.`schRoom`
WHERE `s`.`schDiscipline` = `l`.`lnkDiscipline`
GROUP BY `s`.`schWeekDay`
ORDER BY `s`.`schWeekDay`, `s`.`schStartAt`'
I’d like to return to something like:
Array(
[0] => Array (
[0] => stdClass Object
(
[lnkId] => 61
[schWeekDay] => 1
[dscType] => DI
[dscName] => Nome da Disciplina 1
[schStartAt] => 19:20:00
[rmName] => Sala 1
)
[1] => stdClass Object
(
[lnkId] => 62
[schWeekDay] => 1
[dscType] => DI
[dscName] => Nome da Disciplina 1
[schStartAt] => 20:10:00
[rmName] => Sala 1
)
[1] => stdClass Object
(
[lnkId] => 63
[schWeekDay] => 2
[dscType] => DPDI
[dscName] => Nome da Disciplina 2
[schStartAt] => 19:20:00
[rmName] => Sala 3
)
)
each position could contain only 2 objects?
– Arthur Luiz
There is no limit
– Gustavo Eklund
more Oce wants to separate them by what? or a position containing all objects?
– Arthur Luiz
I want clusters by the day of the week, for example if there is more than one record on the same day, it should create an array to place the lines.
– Gustavo Eklund