目前我正在建立一个论坛,以便学习如何建立一个论坛和一般的实践。我认为这个问题对所有人都有用。
Preview image here. 预览代码如下。
<?php
//1. Perform database query for categories
$sql_categories = "SELECT * FROM categories ORDER BY category_position ASC";
$res_categories = mysqli_query($conn, $sql_categories);
//2. Display returned data from categories
if (mysqli_num_rows($res_categories) > 0) {
while ($array_categories = mysqli_fetch_assoc($res_categories)) {
echo "<div id='category_head'>{$array_categories["category_title"]}</div>";
//3. Perform database query for forums
$sql_forums = "SELECT * FROM forums WHERE forum_category_id = {$array_categories["category_id"]} ORDER BY forum_position ASC";
$res_forums = mysqli_query($conn, $sql_forums);
//4. Display returned data from forums
if (mysqli_num_rows($res_forums) > 0) {
while ($array_forums = mysqli_fetch_assoc($res_forums)) {
echo "<div id='forum_head'>{$array_forums["forum_title"]}</div>";
}
}
}
}
?>
答案 0 :(得分:0)
与echo
类别标题相同的方式,为什么不同时echo
ID?
echo "<div id='category_{$array_categories["category_id"]}'>{$array_categories["category_title"]}</div>";