【发布时间】:2019-11-13 14:12:30
【问题描述】:
我正在用来自数据库的信息填充一个 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);
?>
【问题讨论】:
-
你能解释一下你想让按钮做什么吗?
-
使用我现在拥有的代码,表格会自动填写,但我希望它在我点击按钮后填写
-
我认为您只是在寻找 onclick 事件。
-
是否可以重新加载页面,或者您是否尝试在不重新加载的情况下这样做?如果您不想重新加载页面,则需要使用 AJAX。
-
我不介意它是否会重新加载,但如果不是太麻烦的话,我想知道如何双向进行