我将使用 php 动态创建一个 HTML 表单。使用该表格,用户可以选择不同类别下的主题。一个类别及其主题已分解为一个逻辑部分并应用了 jquery 手风琴。在我的表单中,我需要创建更多这样的逻辑部分。
// Check SESSION fromm category page
if ( isset ( $_SESSION['category']) && is_array( $_SESSION['category'])) {
$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 = array();
$subjects[] = $row['sn'];
echo '<div>';
//Detect change in category
if($catID != $categoryId)
{
echo "<h3>Category 01: <span>{$category}</span><span></span></h3>";
echo "<div class='container'>";
echo '<table>';
$j = 0;
foreach ( $subjects AS $sub ) {
if($j%2 == 0 && $j == 0)
{
echo '<tr>';
echo '<td width="50%"><input type="checkbox" value="1" name="subjects[]">'.$sub.'</td>';
}
else if($j%2 == 0)
{
echo '</tr><tr>';
echo '<td width="50%"><input type="checkbox" value="1" name="subjects[]">'.$sub.'</td>';
}
echo '<td width="50%"><input type="checkbox" value="1" name="subjects[]">'.$sub.'</td>';
$j++;
}
echo '</tr>';
echo '</table>';
echo "</div> <!-- End .container DIV -->\n";
}
$catID = $categoryId;
echo '</div>';
}
}