我正在使用数据库中的信息填充 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 上的这个问题 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>
关于php - 如何使用HTML按钮来触发功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56860773/