简体   繁体   English

能够检查表单元格NOT是否等于null,如果是,则删除/隐藏单元格中的按钮

[英]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'. 我想知道是否有可能隐藏按钮,如果表格单元格中有某种信息,或者行(技术人员)不等于“ NULL”。 It's kinda annoying to have a button there, when there's no use for it after 1 click. 如果单击1次后没有任何用处,那会有点烦人。

My database (table name: assignment): 我的数据库(表名:assignment):

| ID | CustomerID | Name | Address | Technician |

My PHP: 我的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. 当他们按下按钮时,数据库UPDATE的行即已完成分配的表格单元中就不需要按钮了。

take a column in database for manage the button status called is_taken . 在数据库中的一列中管理名为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. 渲染HTML时,请检查is_taken列的状态。 Now your html will be like below:- 现在,您的html将如下所示:-

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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