1
我想在while循環中顯示一個表..但我已經卡住了2天。任何人都可以幫助我做到這一點?在數據庫值的foreach循環中顯示一個表
現在我將解釋實際上我在這裏要做的事情。在我的數據庫中有幾個類別和幾個主題。每個類別都有自己的主題。現在我需要顯示類別及其主題作爲列表。當在特定的類別顯示科目我需要添加一個HTML表格2列,顯示對象..
這是我迄今所做的代碼..
$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中顯示科目表。
請問有沒有人可以幫助我們解決這個問題......?
謝謝...
然後我可以得到這個錯誤..:爲foreach提供的無效參數() – TNK
我更新了代碼,嘗試一下,檢查輸出是否相同? – Nalaka526
然後腳本將其他部分..別的 \t \t \t { \t \t \t \t echo「