我有以下 MySQL 数据库:
| id | sessionId | time |
|------------|-------------|---------------------|
| 54 | 4 | 2013-03-23 09:00:00 |
| 55 | 4 | 2013-03-23 09:15:00 |
| 56 | 5 | 2013-04-20 01:00:00 |
| 57 | 5 | 2013-04-20 15:15:00 |
| 58 | 5 | 2013-04-20 19:15:00 |
我试图这样返回一个数组:
Array
(
[0] => Array
(
[sessionId] => 4
[time] => Array
(
[0] => 2013-03-23 09:00:00
[1] => 2013-03-23 09:15:00
)
)
[1] => Array
(
[sessionId] => 5
[time] => Array
(
[0] => 2013-04-20 01:00:00
[1] => 2013-04-20 15:15:00
[2] => 2013-04-20 19:15:00
)
)
)
到目前为止运行此查询
$result = mysql_query("SELECT * FROM `Exercise_Lists_New` WHERE `patientId` = 381");
$row = mysql_fetch_assoc($result);
while($row = mysql_fetch_array($result)){
$sessionIds[] = array("sessionId" =>$row['sessionId'], "time" => array($row['time']));
}
print_r($sessionIds,true);
给我以下
Array
(
[0] => Array
(
[sessionId] => 4
[time] => Array
(
[0] => 2013-03-23 09:00:00
)
)
[1] => Array
(
[sessionId] => 4
[time] => Array
(
[0] => 2013-03-23 09:15:00
)
)
[2] => Array
(
[sessionId] => 5
[time] => Array
(
[0] => 2013-04-20 01:00:00
)
)
[3] => Array
(
[sessionId] => 5
[time] => Array
(
[0] => 2013-04-20 15:15:00
)
)
[4] => Array
(
[sessionId] => 5
[time] => Array
(
[0] => 2013-04-20 19:15:00
)
)
)
所以我想将所有共享相同“sessionId”的“时间”组合在一起。使用 php.ini 执行此操作的最佳方法是什么?
谢谢