简体   繁体   中英

Able to check if the table-cell NOT equals null, if so remove/hide button in the cell

I'm wondering if it's possible to hide a button, if there's some kind information in the table-cell or the row (technician) is not equals to 'NULL'. It's kinda annoying to have a button there, when there's no use for it after 1 click.

My database (table name: assignment):

| ID | CustomerID | Name | Address | Technician |

My PHP:

<?php 
if(isset($_POST['customerButton'])){
    $ID = $_POST['assignment_id'];
    $user = $row_Users['username']; <--- // Name of the logged in user.

    mysql_query("UPDATE assignment SET technician = '$user' WHERE ID='$ID'"); <--- //Not sure what to put after 'WHERE'. 
}

?>

Here's a snippet of the dynamic table

<td><?php echo $row_Assignment['address']; ?></td>
<td>
<?php echo $row_Assignment['technician']; ?>

<form action="" method="post"> 

    <input type="hidden" name="assignment_id" value="".$row_Assignment['ID']."">                                 
    <input type="submit" name="customerButton" id="customerButton" value="Add">

</form>
</td>

Thanks!

Edit: The purpose of the code above is to let one of my technicians to be able to take an assignment. And when they've pressed the button, the row in the database UPDATE's and therefore there's no need to have a button in the table-cell, when the assignment is already taken.

take a column in database for manage the button status called is_taken . and update this column when the technician click on the button. When the HTML is rendering check the status of is_taken column. Now your html will be like below:-

<td><?php echo $row_Assignment['address']; ?></td>
<td>
<?php echo $row_Assignment['technician'];
   if($row_Assignment['is_taken']==0){ ?>
    <form action="" method="post"> 
      <input type="hidden" name="assignment_id" value="".$row_Assignment['ID']."">                                 
      <input type="submit" name="customerButton" id="customerButton" value="Add">
<?php }
  else{
         // do as you want to replacing with button
      }
?>
   </form>
</td>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM