If you keep clicking on the previous page, the limit is 0, and if you keep clicking on the next page, the limit is 4. If you keep clicking on the homepage, an error will be reported.
心境
心境 2018-07-26 14:45:57
0
2
1147

include 'connection.php';



$count_sql = 'select count(id) as c from user';


$result = mysqli_query($conn, $count_sql);


$data = mysqli_fetch_assoc($result);


//得到总的用户数

$count = $data['c'];


$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;


/*

if (isset($_GET['page'])) {

    $page = (int) $_GET['page'];

} else {

    $page = 1;

}

 */


//每页显示数


$num = 5;


//得到总页数

$total = ceil($count / $num);


if ($page <= 1) {

    $page = 1;

}


if ($page >= $total) {

    $page = $total;

}



$offset = ($page - 1) * $num;


$sql = "select id,username,createtime,createip from user order by id desc limit $offset , $num";


$result = mysqli_query($conn, $sql);


if ($result && mysqli_num_rows($result)) {


    //存在数据则循环将数据显示出来


    echo '<table width="800" border="1">';


    while ($row = mysqli_fetch_assoc($result)) {


        echo '<tr>';


        echo '<td>' . $row['username'] . '</td>';

        echo '<td>' . date('Y-m-d H:i:s', $row['createtime']) . '</td>';

        echo '<td>' . long2ip($row['createip']) . '</td>';

        echo '<td><a href="edit.php?id=' . $row['id'] . '">编辑用户</a></td>';

        echo '<td><a href="delete.php?id=' . $row['id'] . '">删除用户</a></td>';


        echo '</tr>';

    }


echo '<tr><td colspan="5"><a href="page.php?page=1">Homepage</a> <a href="page.php ?page=' . ($page - 1) . '">Previous page</a> <a href="page.php?page=' . ($page 1) . '">Next Page</a> <a href="page.php?page=' . $total . '">Last page</a> The current page is ' . $page . 'Page total' . $total . 'Page</td></tr>';


## echo '</table>';


} else {

echo 'No data';

}


mysqli_close($conn);


心境
心境

reply all(2)
心境

echo '<tr><td colspan="5"><a href="page_divide.php?page=1">Homepage</a>

<a href="page_divide.php?page=' . ($page==1?1:$page-1). '">Previous page</a>

<a href=" page_divide.php?page=' . ($page ==$total?$total:$page+1) . '">Next page</a>

<a href="page_divide .php?page=' . $total . '">Last page</a>

The current page is ' . $page . 'Page total' . $total . 'Page</td> </tr>';


心境

solved

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template