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