数据库结构:
ID | USERID | ENTRYDATE | EXITDATE | PRICE | ROOMID
-----------------------------------------------------
1 | 2 | 2012-10-1 | 2012-10-4| 100 | 1
2 | 2 | 2012-10-1 | 2012-10-4| 100 | 2
3 | 2 | 2012-10-1 | 2012-10-4| 100 | 3
4 | 2 | 2012-10-6 | 2012-10-9| 100 | 4
5 | 2 | 2012-10-6 | 2012-10-9| 100 | 55
我需要一些帮助。我想从这个数据库中显示一组记录。我想显示具有相同USERID的所有那些,但是在同一个DIV中对具有相同ENTRYDATE和EXITDATE的那些进行分组。例如,结果应该是这样......
ID | USERID | ENTRYDATE | EXITDATE | PRICE | ROOMID
------------------------------------------------------
1 | 2 | 2012-10-1 | 2012-10-4| 100 | 1
2 | 2 | 2012-10-1 | 2012-10-4| 100 | 2
3 | 2 | 2012-10-1 | 2012-10-4| 100 | 3
ID | USERID | ENTRYDATE | EXITDATE | PRICE | ROOMID
----------------------------------------------------
4 | 2 | 2012-10-6 | 2012-10-9| 100 | 4
5 | 2 | 2012-10-6 | 2012-10-9| 100 | 5
答案 0 :(得分:0)
我不确定我是否理解你的问题。我假设你有一个字符串索引数组,你想根据ENTRYDATE和EXITDATE值拆分它。也许是这样的:
$currentEntry = $data[0]['ENTRYDATE'];
$currentExit = $data[0]['EXITDATE'];
$splitted = array();
$i = 0;
foreach ($data as $row) {
if ($row['ENTRYDATE'] == $currentEntry && $row['ENTRYDATE'] == $currentExit) {
$splitted[$i] []= $row;
} else {
$currentEntry = $row['ENTRYDATE'];
$currentExit = $row['EXITDATE'];
$i++;
}
}