我正在尝试打印类似这样的列表....
Catagory 01 subjects1 subjects4 subjects2 subjects5 subjects3 subjects6 Catagory 02 subjects1 subjects4 subjects2 subjects5 subjects3 subjects6 Catagory 03 subjects1 subjects4 subjects2 subjects5 subjects3 subjects6
一类有自己的科目。目前我有类别 ID 并创建了一个查询来获取其类别名称和拥有的主题。这是我创建的查询..
$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 = 假;
而 ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<div>';
if ( $catID != $row['ci']) {
echo '<h3>Category 01: <span>' . $row['cn'] . '</span><span></span></h3>';
}
echo '<div class="container">';
echo '<p>' . $row['sn']. '</p>'; // This subjects I need to display in a table with 2 columns..
$catID = $row['ci'];
echo '</div>';
echo '</div>';
}
有人可以帮助我吗?非常感谢您的想法和意见。
谢谢你。