dongluxin2452 2017-05-11 07:39
浏览 121
已采纳

如果满足条件,如何在while循环中跳转一行

I have created a form which managers can create users for the system. I have a separate table which contains user types Ex: Admin, Manager ... etc.

I use a while loop in my form to drag the above mentioned user roles from the table and draw a set of radio buttons.

My problem is I want to hid the Admin option from the normal manager I used PHP but it only hides the radio button it self not the text next to it my code is below.

Code:

<div id="userRoles">
 <label for="userRoles">User Role:</label><br>
  <?php while ($row = $getUserRoleQuery -> fetch(PDO::FETCH_ASSOC)) { ?>
   <input type="radio" class="userRoles" name="userRoles"
    value="<?php echo $row["urId"]; ?>" <?php if ($_SESSION["uRole"] == "1" && $row["userRole"] == "Admin" ){?> hidden <?php } ?>><?php echo $row["userRole"]; }?>
</div>

I'm thinking of making the while loop skip that 1st line using an IF ... ELSE but I can't get my head around how to do it.

I just want to hide the Admin option.

UPDATE: With the help of mplungjan and Alive to Die I got this problem solved I used the continue method which was more streamline from my point of view now my code looks like this;

Code:

<div id="userRoles">
 <label for="userRoles">User Role:</label><br>
 <?php while ($row = $getUserRoleQuery -> fetch(PDO::FETCH_ASSOC)) {
  if ($_SESSION["uRole"] !== "1" && $row["userRole"] == "Admin" ) continue ?>
  <input type="radio" class="userRoles" name="userRoles" value="<?php echo $row["urId"]; ?>"><?php echo $row["userRole"]; }?>
</div>
  • 写回答

2条回答 默认 最新

  • dongshi1880 2017-05-11 07:59
    关注

    You can use an if and continue - statements after the continue are ignored

    use OR (||) if either uRole==1 or Admin should be skipped

    <?php while ($row = $getUserRoleQuery -> fetch(PDO::FETCH_ASSOC)) { 
       if ($_SESSION["uRole"]=="1" && $row["userRole"] == "Admin") continue; // ignore the rest of the loop
    ?>
        <input type="radio" class="userRoles" name="userRoles" value="<?php echo $row["urId"]; ?>"><?php echo $row["userRole"]; }}?>
    }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大