Home > Net >  How to hide a button according to a Rule
How to hide a button according to a Rule

Time:05-31

I have a button which makes a function to edit a row in mysql table. The button is as follows,

<td><input type="button" name="edit" value="UPDATE" id="<?php echo $row["ID"]; ?>"  /></td>

The button can be find inside a table as follows,

<div id="employee_table">
     <table >
     <tr>
    <th width="30%">Username</th>
     <th width="10%">Change</th>
      </tr>
      <?php
      while($row = mysqli_fetch_array($result))
      {
      ?>
      <tr>
       <td><?php echo $row["username"]; ?></td>
        <td><input type="button" name="UPDATE" value="Mark as Received" id="<?php echo $row["ID"]; ?>"  /></td>
      
       
      </tr>
      <?php
      }
      ?>
     </table>
    </div>

I need to hide my UPDATE button by checking the value of a mysql field, like below;

if($row["username"]=='John')
{
//hide button
}
else{
//show UPDATE button
}

To get a better understanding I will put a table as well,,

enter image description here

can someone show me how to do this?

CodePudding user response:

Just enclose the button with if statement like this

<td>
    <?php if($row["username"]!='John'){ ?>
         <input type="button" name="UPDATE" value="Mark as Received" id="<?php echo $row["ID"]; ?>"  />
    <?php } ?>
</td>
  • Related