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 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效