我希望第一学期S.Y 2013 只显示一次。但是在我的代码中,它会多次显示,因为它在循环中。有没有其他方法可以做到这一点?
这里是循环
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Subject Code</th>
<th>Decription</th>
<th>Grade</th>
<th>Units</th>
</tr>
</thead>
<tbody>
<?php
$sql ="SELECT * FROM grades WHERE stud_no ='$stud_no'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td></td>
<td><?php echo $row['semester']. "st Semester S.Y " .$row['sch_year'];?></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo $row['subj_cd'];?></td>
<td><?php echo $row['subj_descr'];?></td>
<td><?php echo $row['final_grade'];?></td>
<td><?php echo $row['units_lec'] + $row['units_lab'];?></td>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
答案 0 :(得分:1)
<?php
$sql ="SELECT * FROM grades WHERE stud_no ='$stud_no'";
$result = mysqli_query($con, $sql);
var $check=1; //added line
while($row = mysqli_fetch_array($result)){
?>
然后使用if条件来实现您的目标
<td><?php
if($check==1){
echo $row['semester']. "st Semester S.Y " .$row['sch_year'];
$check=0;
}
?></td>