[英]How to show only 1 row on index
I am using Arduino, ESP8266 to send data sensor to localhost. 我正在使用Arduino,ESP8266将数据传感器发送到localhost。 See image below, I don't know to to make at the index.php only show 1 latest data only on 1 row like the rectangle with red color in the image. 参见下图,我不知道要在index.php上仅在1行上显示1个最新数据,例如图中带有红色矩形的矩形。
<?php
include("dbcon.php");
$link=$cn;
$i=0;
$result=mysqli_query($link,"SELECT * FROM `node` where 1");
?>
<html>
<head>
<title>Sensor Data1</title>
<meta http-equiv="refresh" content="30">
</head>
<body>
<Center><h1>Sensor Readings</h1>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td> No </td>
<td> Waktu / Tarikh </td>
<td> Temperature </td>
<td> Humidity </td>
<td> Length(CM) </td>
<td> Node </td>
</tr>
<?php
while($row = mysqli_fetch_array($result)) {
printf("<tr><td> %d </td><td> %s </td><td> %s </td><td> %s </td><td> %s </td><td> %s </td></tr>",
++$i, $row["tarikh"], $row["temperature"], $row["humidity"], $row["height"], $row["node"]);
}
?>
<script type="text/javascript">
document.write ('<p>Waktu sekarang: <span id="date-time">', new Date().toLocaleString(), '<\/span>.<\/p>')
if (document.getElementById) onload = function () {
setInterval ("document.getElementById ('date-time').firstChild.data = new Date().toLocaleString()", 50)
}
</script>
</table></center>
</body>
</html>
From the attached image it looks like you want to limit the output to a single row , not a single column . 从所附的图像,它看起来像你想的输出限制为单行 ,而不是单个列 。 You could do this using a combination of the order by
and limit
clauses: 您可以结合使用order by
和limit
子句来做到这一点:
SELECT * FROM `node` ORDER BY `waktu` DESC LIMIT 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.