php - 如何使用 HTML 按钮触发功能?
问题描述
我正在使用来自数据库的信息填充 HTML 表,并希望使用按钮触发它。
有人可以帮我解决这个问题,也许可以通过示例添加一些指向相关网站的链接吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div method="GET">
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
</tr>
<?php
include "php/populate.php";
?>
</thead>
</table>
<input type="button" value="button" id="button">
</div>
</body>
</html>
<?php
$result = mysqli_query($enlace,"SELECT * FROM tb_personas");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['txt_nombre'] . "</td>";
echo "<td>" . $row['txt_usuario'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($enlace);
?>
解决方案
您需要使用 jQuery(使用 ajax 的最简单方法)
在stackoverflow上查看this question how to call a php script on a html button click
此外,您将数据包含在表的标题中,而不是它们应该包含在表的正文中。
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
</tr>
</thead>
<tbody>
<?php include "php/populate.php"; ?>
</tbody>
</table>
推荐阅读
- swift - Segue 过渡到错误的页面 Swift Xcode
- javascript - 向 select2-container 添加一个额外的自定义类
- python - 具有用户名和密码的 Paramiko,无密钥 - 糟糕,未处理的类型 3(“未实现”)
- excel - 循环通过 ListBox 将值输入工作表数组
- r - 如何随机生成在另一个日期和时间之后发生的日期和时间
- kubernetes - istio 上游连接错误或在标头之前断开/重置。重置原因:连接终止
- php - $_POST 在 nginx 上为空
- c++ - 如何启动与主文件夹位于同一子文件夹中的 exe?(C++)
- angular - 如何从字段创建 Observable
- linux - 通过 ssh (svn+ssh) 只读访问 svn 存储库