我想转换这个 MySQL 表:
title1 | title2 |type
-------+--------+----
qwe1 | qwe2 | 3
asd1 | asd2 | 7
到 PHP 中的这个表
title | type
------+-----
asd1 | 7
asd2 | 7
qwe1 | 3
qwe1 | 3
但我不知道如何正确地按第一列对 PHP 表进行排序。
(这是我目前使用的代码)
$sql = "SELECT * FROM table ORDER BY title1, title2";
$pager = new PS_Pagination( $dbh, $sql, 3, 4, null );//pagination class
$rs = $pager->paginate();
while ($row = $rs->fetch(PDO::FETCH_ASSOC)){
echo "<tr>";
echo "<td>{$row['title1']}</td>";
echo "<td>{$row['type']}</td>";
echo "</tr>";
echo "<tr>";
echo "<td>{$row['title2']}</td>";
echo "<td>{$row['type']}</td>";
echo "</tr>";
}
echo "</table>";