php - 如何根据给定的字符串和按下按钮时隐藏从数据库中获取信息的表行
问题描述
给出了一个 HTML 表,其中有人(在本例中为代理)显示了以下信息 Id、Name、Rank、Location 和Status。状态可以有 3 个值。在线,离线,断开连接。根据其中一个代理的状态,我想放置 3 个按钮,例如在线、离线和断开连接,并在按下按钮时隐藏具有不同值的其他行。例如,如果我按 Online,HTML 端包含状态 Offline 和 Disconnected 的表格行会消失,这也适用于其他人。我不知道实现我之前所说的,我对任何被认为可以解决我的问题的解决方案持开放态度。
<table id="main_table">
<tr>
<td>Id</td>
<td>Agent Name</td>
<td>Agent Rank</td>
<td>Agent Location</td>
<td>Status</td>
</tr>
<?php
require 'CMS/processing/conn.php';
$result = mysqli_query($con,"SELECT * FROM agents");
while($info = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['id']; ?></td>
<td><?php echo $info['agentName']; ?></td>
<td><?php echo $info['agentRank']; ?></td>
<td><?php echo $info['locationNames']; ?></td>
<td><?php echo $info['agentStatus']; ?></td>
</tr>
<?php
}
?>
</table>
解决方案
尝试使用以下逻辑:创建 3 个按钮<a>
并将状态值作为 GET 传递到同一页面,然后在获取时检查它是否具有 GET
注意:这不是答案:将直接 GET 值传递给 sql 查询可能会导致一些安全问题
<a href="?status=1" class="btn">Online</a>//put the status value based on your status
<a href="?status=2" class="btn">Offline</a>//put the status value based on your status
<a href="?status=3" class="btn">Disconnected</a>//put the status value based on your status
<table id="main_table">
<tr>
<td>Id</td>
<td>Agent Name</td>
<td>Agent Rank</td>
<td>Agent Location</td>
<td>Status</td>
</tr>
<?php
require 'CMS/processing/conn.php';
if(isset($_GET['status']))
{
$result = mysqli_query($con,"SELECT * FROM agents where agentStatus='".$_GET['status']."'");
}
else
{
$result = mysqli_query($con,"SELECT * FROM agents");
}
while($info = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['id']; ?></td>
<td><?php echo $info['agentName']; ?></td>
<td><?php echo $info['agentRank']; ?></td>
<td><?php echo $info['locationNames']; ?></td>
<td><?php echo $info['agentStatus']; ?></td>
</tr>
<?php
}
?>
</table>
推荐阅读
- reactjs - 为什么 redux 只在浏览器刷新时更新?
- api - Tweepy - 有没有办法在 Twitter 上找到你的朋友之间的所有共同友谊?
- linechart - Vegalite - 忽略 NaN 和空值
- dynamics-crm - 无法在业务流程中添加工作流显示名称
- javascript - 如何在 VueJs 中使用 axios 创建 api 服务?
- mysql - MySQL Workbench 无法检测到任何正在运行的 MySQL 服务器。解决方案?
- linux - Bash 脚本说它在我的终端上有无效的选项
- sql - 为什么不应该在 SQL 模式中表示冗余状态?
- python - 在功能性 Keras API 中使用 tf.keras.metrics.Mean 时出错
- linux - 在远程主机上运行 SSH 命令时,如何阻止美元符号在变量中扩展?