John Davidson

php - How to hide a button according to a Rule

0 comments
Message:


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"]; ?>" class="btn btn-info btn-xs edit_data" /></td>

The button can be find inside a table as follows,


<div id="employee_table">
<table class="table table-bordered">
<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"]; ?>" class="btn btn-info btn-xs edit_data" /></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,,



can someone show me how to do this?



My Answer:
You can achieve this by adding a conditional statement within the loop that generates the buttons. Here's an example of how you can hide the UPDATE button based on the value of the "username" field in the MySQL table:

php






while($row = mysqli_fetch_array($result)) {
?>




}
?>
Username Change

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




In the above code, we added an if-else statement inside the loop that checks if the value of the "username" field is equal to 'John'. If it is, the UPDATE button will not be displayed. Otherwise, the UPDATE button will be shown as before.

Rate this post

5 of 5 based on 5657 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us