我已经看了几个例子,但似乎都没有改变结果。无论如何配置,分页都不会显示。当您检查页面时,会看到该部分的内容,但没有页面链接。我不确定这是否与将服务器移植到noip主机名有关,或者我的数据库未配置为使用此选项的权限
<html>
<head>
<title>Sensor data</title>
</head>
<body>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
<h1 align="center">Voltage / Current sensor readings</h1>
<p align="center">These are our values coming from the sensors. They are being inserted into a database using a python script that automatically reads the serial port on the pi,
that is connected to the Arduino.</p>
<p align="center">This script is reading every second uploading the data and then is being displayed within this table.</p>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "sensors";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error){
die("Connection failed: " .$conn->connect_error);
}
$limit = 10;
if (isset($_GET["page"])) { $page = $_GET["page"];} else {$page = 1;};
$start_from = ($page-1) * $limit;
$sql = "SELECT * FROM sensorInfo ORDER BY time DESC LIMIT $start_from, $limit";
$result = $conn->query($sql);
?>
<table border="1" cellspacing="1" cellpadding="1" align="center">
<thead>
<tr>
<th> Timestamp </th>
<th> Solar Panel Voltage </th>
<th> Solar Panel Current </th>
<th> Solar Panel Power </th>
<th> Turbine Voltage </th>
<th> Turbine Current </th>
<th> Turbine Power </th>
<th> Grid Voltage </th>
<th> Grid Current </th>
<th> Grid Power </th>
<th> Pump Voltage </th>
<th> Pump Current </th>
<th> Pump Power </th>
</tr>
</thead>
<tbody>
<?php
while($row = $result->fetch_assoc()) {
printf("<tr><td> %s </td><td> %s </td><td> %s </td><td> %s </td>
<td> %s </td><td> %s </td><td> %s </td>
<td> %s </td><td> %s </td><td> %s </td>
<td> %s </td><td> %s </td><td> %s </td></tr>",
$row["time"], $row["sp_voltage"], $row["sp_current"], $row["sp_power"],
$row["t_voltage"], $row["t_current"], $row["t_power"],
$row["g_voltage"], $row["g_current"], $row["g_power"],
$row["p_voltage"], $row["p_current"], $row["p_power"]);
};
?>
</tbody>
</table>
<ul class = "pagination">
<?php
$sql = "SELECT COUNT(id) FROM sendorInfo";
$results = $conn->query($sql);
$row = $result->num_rows;
$total_records = $row[0];
$total_pages = ceil($total_records / $limit);
for ($i = 1; $i <= $total_pages; $i++) {
echo "<a href='index.php?page=".$i. "'>".$i."</a>";
}
?>
</ul>
</body>
</html>