php - 如何使用HTML按钮来触发功能?

标签 php html mysql xampp

我正在使用数据库中的信息填充 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/

相关文章:

jquery - 给一个class下的所有h3标签应用anchor标签

php - Ubuntu 16.04 缺少 mbstring 扩展

php - 在 WordPress 之外获取具有自定义尺寸的特色图像

PHP相当于Excel的MROUND函数,四舍五入到最接近的倍数

html - 菜单 CSS 在 IE11 中无法正常工作

html - 页脚图标未对齐

MySQL从另一个表中获取数据,其中列行与第一个表中的行结果匹配

C# MySql 将数据库中特定行的参数从一种表单传递到另一种表单

java - 这个持久性单元配置有什么问题?

php - 更新后 Atom 编辑器中的 @php 而不是 <?php