フェッチ行をデータのグループに出力するにはどうすればよいですか? たとえば、データベースにこれらがあります
title category
one number
two number
three number
a letter
b letter
c letter
別のテーブルに印刷したかったのです。
table1 table2
number letter
one a
two b
three c
これが私が試したことです。
$select = "SELECT * FROM `table` ORDER BY `category`";
$result = mysql_query($select);
$current_cat = null;
while ($rows = mysql_fetch_array($result))
{
if ($rows["category"] != $current_cat)
{
$current_cat = $rows["category"];
echo "<p>$current_cat</p>";
}
echo"$rows[title]";
}
これらのコードの出力は次のようになります
number
one
two
three
letter
a
b
c
しかし、もう一度、別のテーブルにしたかったのです。