私はIDに基づいてカテゴリに結果を表示しようとしています。データベースから情報を取得しますが、カテゴリのヘッダーが再び作成されます。例えばグループ化データベースからの結果
:
タイトルカテゴリのデモ猫1
トピック1匹の猫1タイトルカテゴリのデモ猫1
トピック2猫1タイトルカテゴリのデモ猫2
トピック3 cat 2
た場合、それが表示されるはずです:
タイトルカテゴリのデモ猫1
トピック1匹の猫1トピック2猫1
タイトルカテゴリのデモ猫2
トピック3猫2
<table class="table table-bordered table-hover">
<?php
$sql = "SELECT * FROM forums, forum_categories WHERE forum_categories.cat_id = forums.cat_id ORDER BY forum_categories.cat_id";
$result = query($sql);
while (($row = mysqli_fetch_assoc($result)) != false) {
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<thead>";
echo "<tr>";
echo "<th colspan='4'>$cat_title</th>";
"</tr>";
echo "</thead>";
echo "<tbody>";
$forums_cat_id = $row['cat_id'];
$forum_name = $row['forum_name'];
$forum_desc = $row['forum_desc'];
$forum_last_post_id = $row['forum_last_post_id'];
echo "<tr>";
echo "<td>$forums_cat_id</td>";
echo "<td>$forum_name<br>$forum_desc<br>Admin</td>";
echo "<td>0</td>";
echo "<td>0</td>";
echo "</tr>";
}
?>
</tbody>
</table>
あなたがすでに出力しているヘッダーを追跡し、変更時にのみ新しいヘッダーを出力します。例えば'$ prev = null; while(...){if($ prev!= $ cur){出力する$ cur; $ prev = $ cur; }} ' –
Marc B助けてくれてありがとう私はかなり新しいPHPです。私にそれを説明できますか? –