我正在尝试在一段时间循环中显示一个表格。但我已经卡在那里 2 天了。任何人都可以帮我做到这一点?
现在我将实际解释我在这里要做什么。我的数据库中有几个类别和几个主题。每个类别都有自己的主题。现在我需要将类别及其主题显示为列表。当显示特定类别下的主题时,我需要添加一个包含 2 列的 HTML 表格来显示主题..
这是我到目前为止所做的代码..
$categoryIds = implode(',', $_SESSION['category']);
$q = "SELECT c. category_id AS ci, c.category_name AS cn, s.subject_name AS sn, s.subject_id AS si
FROM category AS c
INNER JOIN category_subjects AS cs ON cs.category_id = c.category_id
INNER JOIN subjects AS s ON s.subject_id = cs.subject_id
WHERE c.category_id IN ($categoryIds)";
$r = mysqli_query( $dbc, $q) ;
$catID = false;
$max_columns = 2;
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
{
$categoryId = $row['ci'];
$category = $row['cn'];
$subjects = $row['sn'];
echo '<div>';
//Detect change in category
if($catID != $categoryId)
{
echo "<h3>Category 01: <span>{$category}</span><span></span></h3>\n";
foreach ( $subjects AS $sub ) {
echo "<div class='container'>\n";
//echo "<table><tr>\n";
//echo $sub;
echo "</div> <!-- End .container DIV -->\n";
}
echo '</div>';
}
$catID = $categoryId;
echo '</div>';
}
在这里,类别名称在标签下正确显示。但问题是当要显示属于类别的主题时。我正在尝试在 .container Div 中显示主题表。
请问有没有人可以帮助我解决这个问题......?
谢谢...