1)SELECT colA, colB FROM your_table
2)将数据保存在关联数组中;
$colAdata=array();
$colBdata=array();
foreach ($results as $r) {
if ($r["colA"]=="a")
$colAdata[] = $r;
else
$colBdata[] = $r;
}
3) 根据它们对应的 col 打印:
echo "<table>";
echo "<tr>";
echo "<td>A</td>";
foreach ($colAdata as $r)
echo "<td>".$r["colB"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>B</td>";
foreach ($colBdata as $r)
echo "<td>".$r["colB"]."</td>";
echo "</tr>";
echo "</table>";
更新
2)
foreach ($results as $r) {
$item = $r["colA"];
if (!isset($coldata[$item])
$coldata[ $item ] = $r;
}
3)
$possibilities=array_keys($coldata);
foreach ($possibilities as $p) {
echo "<tr>";
echo "<td>$p</td>";
foreach ($coldata[$p] as $r)
echo "<td>".$r["colB"]."</td>";
echo "</tr>";
}