如何使特定的liwhile循环中处于活动状态?指标将是GET的值,该值是$subj = $_GET['subjdescr'];我对javascript和CSS不好。有人可以给我一些想法吗?或线索。

如果我单击英语2,我希望英语2处于活动状态。否则,如果我单击数学,该数学将处于活动状态。
javascript - 我如何才能使特定的li在while循环内处于事件状态-LMLPHP

这是我的代码。

    <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>

最佳答案

使用静态变量进行检查

<?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;
          }
         ?>

10-06 00:19