How in PDOStatement->fetchAll use PDO::FETCH_GROUP for grouping more than one column simultaneously?
| From: | Михаил Гаврилов | Date: | Tue, 10 May 2011 20:03:37 +0000 |
| Subject: | How in PDOStatement->fetchAll use PDO::FETCH_GROUP for grouping more than one column simultaneously? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-312753@lists.php.net to get a copy of this message | ||
How in PDOStatement->fetchAll use PDO::FETCH_GROUP for grouping more
than one column simultaneously?
For example
col1 col2 col3 col4
13 p1 1 boroda
13 p1 1 boroda 2
13 p1 2 boroda 3
13 p2 2 boroda 4
13 p2 2 boroda 5
14 p3 2 boroda 6
14 p4 2 boroda 7
14 p4 2 boroda 8
$data = $sth->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP, 2);
Expected result for $data:
Array
(
[13] => Array
(
[p1] => Array
(
[0] => Array
(
[col3] => 1
[col4] => boroda
)
[1] => Array
(
[col3] => 1
[col4] => boroda 2
)
[2] => Array
(
[col3] => 2
[col4] => boroda 3
)
)
[p2] => Array
(
[0] => Array
(
[col3] => 2
[col4] => boroda 4
)
[1] => Array
(
[col3] => 2
[col4] => boroda 5
)
)
)
[14] => Array
(
[p3] => Array
(
[0] => Array
(
[col3] => 2
[col4] => boroda 6
)
)
[p4] => Array
(
[0] => Array
(
[col3] => 2
[col4] => boroda 7
)
[1] => Array
(
[col3] => 2
[col4] => boroda 8
)
)
)
--
Best Regards,
Mike Gavrilov.