我使用while循环从我的数据库输出数据但我需要在我的情况下对特定行进行分组我想将Student no.
和Name
分组为图像2显示。
我当前的输出返回如下图所示:
我要输出:
更新
SQL
$sql = "SELECT * ";
$sql .= "FROM registration ";
$sql .= "WHERE Sem = '{$sem}' ";
if($course !==""){
$sql .= "AND Course = '{$course}' ";
}
if($year_level !==""){
$sql .= "AND YearLevel = '{$year_level}' ";
}
$sql .= "AND SY = '{$sy}' ";
//$sql .= "GROUP BY StudentNumber ";
$sql .= "ORDER BY Lastname, SubjectCode ASC";
$row_set = mysqli_query($con, $sql);
PHP
<?php if(mysqli_num_rows($row_set)){?>
<table class="subjectInProfile" border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Student No.</th>
<th>Student Name</th>
<th>Subject Code</th>
<th>Description</th>
<th>LecUnit/LabUnit</th>
</tr>
<?php while($row = mysqli_fetch_assoc($row_set)){ ?>
<tr>
<td><?php echo htmlentities($row['StudentNumber']); ?></td>
<td><?php echo encodeToUtf8($row['LastName'].', '.$row['FirstName']); ?></td>
<td><?php echo htmlentities($row['SubjectCode']); ?></td>
<td><?php echo htmlentities($row['Description']); ?></td>
<td><?php echo htmlentities($row['LecUnit'].'/'.$row['LabUnit']); ?></td>
</tr>
<?php } mysqli_free_result($row_set); ?>
</table>
<?php } else {
echo "<h1 class=\"noRecordFound\">No record found.</h1>";
}?>
<?php } ?>