分页未显示在网页上

时间:2018-12-05 10:56:27

标签: php mysqli pagination

我已经看了几个例子,但似乎都没有改变结果。无论如何配置,分页都不会显示。当您检查页面时,会看到该部分的内容,但没有页面链接。我不确定这是否与将服务器移植到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>&nbsp;Timestamp&nbsp;</th>
        <th>&nbsp;Solar Panel Voltage&nbsp;</th>
        <th>&nbsp;Solar Panel Current&nbsp;</th>
        <th>&nbsp;Solar Panel Power&nbsp;</th>
        <th>&nbsp;Turbine Voltage&nbsp;</th>
        <th>&nbsp;Turbine Current&nbsp;</th>
        <th>&nbsp;Turbine Power&nbsp;</th>
        <th>&nbsp;Grid Voltage&nbsp;</th>
        <th>&nbsp;Grid Current&nbsp;</th>
        <th>&nbsp;Grid Power&nbsp;</th>
        <th>&nbsp;Pump Voltage&nbsp;</th>
        <th>&nbsp;Pump Current&nbsp;</th>
        <th>&nbsp;Pump Power&nbsp;</th>
    </tr>
    </thead>
    <tbody>
    <?php
        while($row = $result->fetch_assoc()) {
            printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td>
                <td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td>
                <td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td>
                <td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </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>

0 个答案:

没有答案