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) 対応する列に基づいて印刷します。
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>";
}