[英]I want to put this resulting query into a 3 by 3 html table
我正在尝试从我的数据库中获取最近时间的 PPM 值,并在按下“显示所有数据”按钮后将其打印在我的 html 页面中
<?php
$mysqli = new mysqli("localhost","root","","CO");
$sql = "SELECT PPM
FROM sensor S
WHERE Time1=(SELECT MAX(Time1) FROM sensor WHERE ID = S.ID);
";
$result=mysqli_query($mysqli,$sql);
if (!$result) {
die("database connection failed");
}
echo "<table>";
while($data = mysqli_fetch_row($result))
{
echo "<tr>";
echo "<td>$data[0]</td>";
echo "</tr>";
}
echo "</table>";
?>
这是在单列中打印结果,而我想在 3 x 3 表中打印结果,这是 html
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#display").click(function() {
$.ajax({
type: "POST",
url: "index1.php",
dataType: "html",
success: function(response){
$("#tab").html(response);
//alert(response);
}
});
});
});
</script>
</head>
<body>
<h2>CO Sensor Detector</h2>
<p>Table shows different values of CO sensors</p>
<table align="center">
<tr>
<td> <input type="button" id="display" value="Display All Data"> </td>
</tr>
</table>
<div id="responsecontainer" align="center">
<table id="tab">
</table>
</div>
</body>
</html>
抱歉,如果我的问题格式不正确,我是个不懂提问的人。 任何帮助深表感谢。
查看文档https://www.php.net/manual/en/mysqli-result.fetch-row.php
<?php
echo "
<table>
<thead>
<tr>
<th>Fila 1</th>
<th>Fila 2</th>
<th>Fila 3</th>
</tr>
</thead>
<tbody>
";
while($data = mysqli_fetch_row($result))
{
echo "
<tr>
<td> $data[0] </td>
<td> $data[1] </td>
<td> $data[2] </td>
</tr>
";
}
echo "</tbody></table>";
?>
我不知道这个 sql 语句收集什么数据,但类似的东西可以工作
<?php
echo "
<table>
<thead>
<tr>
<th>Fila 1</th>
<th>Fila 2</th>
<th>Fila 3</th>
</tr>
</thead>
";
while($data = mysqli_fetch_row($result))
{
echo "
<tbody>
<tr>
<td> dato[0] </td>
</tr>
<tr>
<td> dato[1] </td>
</tr>
<tr>
<td> dato[2] </td>
</tr>
</tbody>
";
}
echo "</table>";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.