Is there a way to group a "key-value store data" by ID in a multidimensional array?
SQL Tables:
Table 1: App
ID | Name | Release
1 | TinyWings | 2014
2 | WarCraft | 2012
3 | StarCraft | 1998
Table 2: AppInfo
ID | Key | Value
1 | Genre | Casual
1 | Rating | 0+
1 | System | iOS
...
2 | Genre | RTS
2 | Rating | 6+
2 | System | Win
...
3 | Genre | RTS
3 | Rating | 12+
3 | System | Win
...
For the profil php page of the App i use
$app = $statement->fetchAll(PDO::FETCH_KEY_PAIR);
but on the index.php page, i need an array something like this for pagination:
Array (
[0]=> Array (
[Genre]=>[Casual]
[Rating]=>[0+]
[System]=>[iOS]
...)
[1]=> Array (
[Genre]=>[RTS]
[Rating]=>[6+]
[System]=>[Win]
...)
[2]=> Array (
[Genre]=>[RTS]
[Rating]=>[12+]
[System]=>[Win]
...)
)
the only way i have found is to use
MAX(CASE WHEN ... THEN .. END) AS ...
for EVERY KEY in the prepare statement to write the rows into columns, is there a way to use it with PDO::FETCH_KEY_PAIR or an better and easier way?