我有两行具有相同的数据,但只有一个单元格与其他单元格不同: -
Customer Name | No Room | Room Type
Maikle dived 2 single
Maikle dived 1 double
所以我不会像这样在一个单元格上合并客户: -
Customer Name | No Room | Room Type
2 single
Maikle dived
1 double
我如何通过PHP和mysql
来做到这一点答案 0 :(得分:0)
如果您尝试将其输出为HTML,请执行以下操作:
//$source should hold the data from DB
$source = array(
array('Maikle dived' => array('No Room' => 2, 'Room Type' => 'single'),
array('Maikle dived' => array('No Room' => 1, 'Room Type' => 'double'),
);
$result = array();
foreach($source as $item) {
$user = key($item);
$val = current($item);
if(!isset($result[$user])) {
$result[$val] = array();
}
$result[$user][] = $val;
}
然后你可以遍历$ result来构建html
foreach($result as $user => $vals) {
echo $user;
echo '<ul>';
foreach($vals as $val) {
echo '<li>'.$val.'</li>';
}
echo '</ul>';
}