如何为数据来自mysql的div创建分页

时间:2019-07-10 12:03:54

标签: javascript php html sql

我有一个表,其数据来自sql

<div class="card-body--">
    <div class="table-stats order-table ov-h">

        <?php
        // Include config file
        require_once "config.php";

        // Attempt select query execution
        $sql = "SELECT * FROM registers";
        if($result = mysqli_query($link, $sql)){
            if(mysqli_num_rows($result) > 0){
                echo "<table class='table'>";
                echo "<thead>";
                echo "<tr>";

                echo "<th class='serial'>ID</th>";
                echo "<th>Name</th>";
                echo "<th>Phone Number</th>";
                echo "<th>Email</th>";
                echo "<th>Action</th>";
                echo "</tr>";
                echo "</thead>";
                echo "<tbody>";
                while($row = mysqli_fetch_array($result)){
                    echo "<tr>";
                    echo "<td>" . $row['id'] . "</td>";
                    echo "<td>" . $row['firstname'] . "</td>";
                    echo "<td>" . $row['address'] . "</td>";
                    echo "<td>" . $row['id'] . "</td>";
                    echo "<td>";
                    echo "<a href='read.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
                    echo "<a href='update.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
                    echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
                    echo "</td>";
                    echo "</tr>";
                }
                echo "</tbody>";
                echo "</table>";
                // Free result set
                mysqli_free_result($result);
            } else{
                echo "<p class='lead'><em>No records were found.</em></p>";
            }
        } else{
            echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
        }

        // Close connection
        mysqli_close($link);
        ?>
    </div> <!-- /.table-stats -->
</div>
</div> <!-- /.card -->
</div>

问题是所有值都出现在表中,并且表的长度很长,表位于一小部分内,有没有办法使用我的代码创建分页?任何帮助将不胜感激。预先感谢

0 个答案:

没有答案