答案 0 :(得分:0)
我不知道如何存储/检索数据,但这里是我如何进行这样的排序 - 假设设置变量$rows
包含所有行的关联数组(类似于结果基本数据库查询)并假设"供应商"是供应商(TSZ,TSR等)的列名," sku"是SKU列的名称," store_price"是商店价格列的名称:
<?php
$vendorData = [];
foreach( $rows as $row ) {
if( !isset($vendorData[$row['vendor']]) ) {
$vendorData[$row['vendor']] = '';
}
$vendorData[$row['vendor']] .= '<div class="sku">' .
$row['sku'] . '</div>' .
'<div class="price">' . $row['store_price'] . '</div>';
}
foreach( $vendorData as $vendorName => $vendorHTML ) {
echo '<div id="' . $vendorName . '" class="vendor">' .
'<h3 class="name">' . $vendorName . '</h3>' .
'<div class="data">' . $vendorHTML . '</div></div>';
}
?>
答案 1 :(得分:0)
这就是你需要的东西: -
$newDataRow = []
foreach($dataRows as $dataItemRow):
$newDataRow[$dataRows['vendor']][] = $dataItemRow;
endforeach;
$op = '';
foreach($newDataRow as $vandorName => $vandorItemData):
$op .= '<div class="vendor_item_group">';
$op .= '<div class="vendor_name">'.$vandorName.'</div>';
$op .= '<div class="item_group">';
foreach($vandorItemData as $record):
$op .= '<span>'.$record['sku'].'</span>';
$op .= '<span>'.$record['price'].'</span>';
endforeach;
$op .='</div>';
$op .= '</div>';
endforeach;
echo $op;
输出应该是这样的: -
TSZ TSR
TSZ K377 TSR319
2300 2250
TSR319
2300