I want to split table data from a database to different pages, everything is good until now, but when I try to to add (?page=) at the end of the url it doesn't work, it's a wordpress page so the url is (www.example.com/page) , when I add for example (?page=) at the end of the url it transfers me to (www.example.com/page/2) but the data are still the same, I limited it to show 4 records in 1 page.

Here's the code to fetch the data from the db, displaying them in a table and limiting them :

                $servername = "localhost";
                $username = "root";
                $password = "";
                $dbname = "players";

                $conn = new mysqli($servername, $username, $password, $dbname);

                if ($conn->connect_error) {
                    die("Connection failed: " . $conn->connect_error);

                $start = intval($_GET['start']);
                $limit = 4;

                $sql = "SELECT name, id, connections, first_seen, last_seen FROM players ORDER BY id LIMIT {$start}, {$limit}";
                $result = $conn->query($sql);

                if ($result->num_rows > 0) {
                    while($row = $result->fetch_assoc()) {
                        echo "<tr><td>".$row["name"]."</td><td>".$row["id"]."</td><td>".$row["connections"]."</td><td>".$row["first_seen"]."</td><td>".$row["last_seen"]."</td></tr>";
                    echo "</table>";

                else {
                    echo "0 results";

1 Answer 1


Why don't you use another variable name? For example: ?pagenum=....

And then on your code you would read that variable:

$start = isset( $_GET['pagenum'] ) ? intval( $_GET['pagenum'] ) : 1;
  • Did this helped?
    – dbeja
    Jul 21, 2017 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.