當使用cakephp Model-> find()方法時,我想以不同的方式對結果進行分組。cakephp - 如何以不同的方式對結果進行分組?
我的模式是:
`id` int(11) NOT NULL AUTO_INCREMENT,
`deviceid` varchar(255) NOT NULL,
`user_id` int(11) NOT NULL,
`sessionid` varchar(255) NOT NULL,
`ip` text NOT NULL,
`image_type` varchar(100) NOT NULL DEFAULT 'invalid_image',
`filename` text NOT NULL,
`analysis_basic` text COMMENT 'output from the image script',
`analysis_admin` text,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `sessionid` (`sessionid`)
CakePHP中我希望得到一些這樣的事:
Array
(
[0] => Array
(
[Picture] => Array
(
[sessionid] => somevalue
)
[0] => Array
(
[id] => 32
[deviceid] => 5124125
[userid] => 4541221
...and all other fileds
)
[1] => Array
(
[id] => 35
[deviceid] => 5124125
[userid] => 4541221
...and all other fileds
)
)
[1] => Array
(
[Picture] => Array
(
[sessionid] => someothervalue
)
[0] => Array
(
[id] => 38
[deviceid] => 5124454
[userid] => 34241
...and all other fileds
)
[1] => Array
(
[id] => 35
[deviceid] => 5124454
[userid] => 34241
...and all other fileds
)
是可能使用CakePHP?還是有更好的方法來實現類似於上述的東西?如果我可以獲得這樣的結果,我知道[0]元素內的所有記錄具有相同的sessionid ..這就是爲什麼。
我不記得有一個直接的功能,做你想做的蛋糕,你打開'foreach'解決方案嗎? –
@SiGanteng是的,如果我們沒有其他解決方案。或者你知道生成結果集的普通mysql查詢 - 可以很容易地轉換成類似的東西。 – sanandrl
不......在mysql中,'group by'不是將不同的結果分組到數組中,所以。 –