如何让li
循环中的特定while
处于活动状态?该指标将是GET
的值$subj = $_GET['subjdescr'];
我在javascript和css时表现不佳。有人可以给我一些关于如何做到这一点的想法吗?或线索。
如果我点击英语2,我希望英语2处于活动状态。否则,如果我点击数学,数学将是活跃的。
这是我的代码。
<li><ul class="premium-menu nav nav-list collapse in">
<?php
$subj = $_GET['subjdescr'];
$sql ="SELECT enroll_ref FROM std_enrolled WHERE stud_no = '$stud_no'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result)){
$enroll_ref = $row['enroll_ref'];
}
$sql3 ="SELECT DISTINCT subj_descr FROM subj_enrolled WHERE enroll_ref = '$enroll_ref'";
$results = mysqli_query($con, $sql3);
while($row = mysqli_fetch_array($results)){
$subj_descr = $row['subj_descr'];
?>
//i want the value of the subj_descr is equals to the value of get data $subj.
<li <?=$subj_descr=='$subj'?'class="active"':'' ?> ><a href="viewlecture.php?subjdescr=<?php echo $subj_descr;?>"><span class="fa fa-caret-right"></span><?php echo ucwords(strtolower($subj_descr)); ?></a></li>
<?php
}
?>
</ul></li>
答案 0 :(得分:1)
使用staic变量进行检查
<?php
static $i =0;
while($row = mysqli_fetch_array($results)){
$subj_descr = $row['subj_descr'];
?>
<li class="<?php if($i == 0) { echo 'active'; } ?>"><a href="viewlecture.php?subjdescr=<?php echo $subj_descr;?>"><span class="fa fa-caret-right"></span><?php echo ucwords(strtolower($subj_descr)); ?></a></li>
<?php
++$i;
}
?>
答案 1 :(得分:0)
在你的李
中使用一个陈述 while($row = mysqli_fetch_array($results)){
$subj_descr = $row['subj_descr'];
?>
<li <?=$subj_descr=='English 2'?'class="active"':'' ?>><a href="viewlecture.php?subjdescr=<?php echo $subj_descr;?>"><span class="fa fa-caret-right"></span><?php echo ucwords(strtolower($subj_descr)); ?></a></li>
<?php
}
?>