javascript - 从外部 php 文件在 html 文件中添加行
问题描述
我正在尝试找到如何在 html 中的表中插入行,但我想使用外部 php 文件来完成,但可能是另一种解决方案,因为目的是从数据库中获取表并写入它下降到一个html表。
我试图在互联网上查看,但我没有找到与我正在寻找的东西相匹配的东西。
解决方案
你的意思是像这里的“示例1”(https://www.php.net/manual/en/mysqli-result.fetch-assoc.php)吗?
您只需要添加 html 标签即可创建 html 表(table、td、...)。
编辑:
此示例包含 html 标记,应该执行您想要的操作:
<html>
...
<body>
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "database");
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($result = $mysqli->query($query)) {
echo "<table>";
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row['Name'] . "</td><td>" . $row['CountryCode'] . "</td></tr>";
}
echo "</table>";
/* free result set */
$result->free();
}
?>
</body>
推荐阅读
- linux - 无法再安装 Perlapi?
- php - Laravel 组按一种类型的列,并且仅按该类型排序
- android - Android pie - 禁用软件后退按钮会破坏可访问性后退操作
- javascript - 如何在 JQuery 中获取正确的数组长度
- java - java.sql.SQLException:使用 HikariCP [JPA + Hibernate + Guice] 关闭连接
- javascript - 如果另一个数组值等于 x,则获取数组值
- connect - mesos-slave 无法连接没有提供凭据错误
- openlayers - 如何下载地图选定部分的 OSM 图块
- cron - 如何在 Magento 2 中通过管理员动态设置 cron
- networking - 在 net-snmp 上使用 snmpget 发现多个设备的网络