国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

??? ???? ??? PHP ?????? ??

?? ??????? ?? ??? ???, ??? ??, ???? ? ?????? ?????.

??? ???? ??? ??, ?????? ??? ?? ??? ?????, ??? ?? ????? ?????? ??? ??? ?? ????.

?? ?? ????? ??????? ???? ???. ?? ??? ??? ????, ??? ????, ?? ??? ???? ??? ?? ?? ??????. ??? ??? ??? ????? ?? ??? ?? ????.

?? ??? ??? ?? ??? ???? ??? ??? ? ????. ?? ??? ??? ????.

2015-10-13_561c9c5350f16.png

??? ?? ?? config.php? ?? ? ????. ??? ???? ?? ?? ??? ?????. ??? ??? ????.

<?php
//數(shù)據(jù)庫服務(wù)器
define('DB_HOST', 'localhost');
//數(shù)據(jù)庫用戶名
define('DB_USER', 'root');
//數(shù)據(jù)庫密碼
define('DB_PWD', 'secret');
//庫名
define('DB_NAME', 'book');
//字符集
define('DB_CHARSET', 'utf8');
?>

??? ??????? ???? ? ???? ???? ???. Connection.php ??. ??? ??? ????.

<?phpinclude 'config.php';$conn = mysqli_connect(DB_HOST, DB_USER, DB_PWD, DB_NAME);if (mysqli_errno($conn)) {    mysqli_error($conn);    exit;}mysqli_set_charset($conn, DB_CHARSET);
?>

?? ? ??? Connection.php ??? ?? ???? ?????? ??? ??? ? ????.

include 'connection.php';

?? ????? ?? ?? ? ???? ??? ???. ??? ?? ??? ??? ????.

2015-10-13_561c9c536b206.png

????? ?? ?? ??? ????? ???.


元素說明備注
首頁最開始進(jìn)入到頁面的第一頁用get傳參才進(jìn)去時默認(rèn)為1
上一頁當(dāng)前頁減1如果頁碼為第一頁時減1,為應(yīng)該為第一頁
下一頁當(dāng)前頁加1如果為最后一
尾頁最后一頁總條數(shù)除以每頁顯示數(shù)得到總頁數(shù)
當(dāng)前頁當(dāng)前所在的頁碼就是當(dāng)前的頁碼
總頁數(shù)一共有多少個頁面總條數(shù)除以每頁顯示數(shù)

??? ??? ??? ? URL ?? ???? ??? ?? ?? ???? ??? ?? ??? ?????. page.php? ??? ?? ?? ??? ???? ?? ???? ??? ??? ? ????. URL ?? ???? ??? ??? ????.

QQ截圖20161114161938.png

?? ???? ? ? ?? ??? ???(offset)? ??( num) ??? ?? ??.

?? ???, ??

頁碼url中g(shù)et值limit偏移量,數(shù)量
第1頁10,5
第2頁25,5
第3頁310,5
第n頁n(n-1)*5,5


???? 5?? ??? ????? ?????. ??? ??? ???? ???? ??? ??? ????.

offset的值為 (n-1)*5
num 為規(guī)定的5

??? ?? ????? ?????.

1. ???? ??? ????? ?????.

?? ??

通過查詢user表的count(id),得到總數(shù)$count。
$count_sql = 'select count(id) as c from user';

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

$data = mysqli_fetch_assoc($result);

//得到總的用戶數(shù)
$count = $data['c'];

?? ???

page.php ???? ?? ????? url? http://www.php.com/page ???. .php, ?? no ?page=1 ??? ?? ??? ????.

??? ??? ?? ??? ???? ???? ?? ?? ??? ?? ?? $page? ???? ???.

???? ??? ???? ???? ???? ?? ?? ??((int) $_GET['page'])? ?????.

? ?? ?? ??:

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

? ?? ?? ??

if (isset($_GET['page'])) {
    $page = (int) $_GET['page'];
} else {
    $page = 1;
}

??? ???

? ???? ???? ???. ?? ???? ??? ????. ????? 5.6?? ?? ??? ???? ???. ?? 6??? ???.

???? 20.3???? ??? ??? ?? ???? ???? ???. ??? ??? ?? 21? ?????.

? ??? ?? ? ???? ???? ??? ?? ?? ??? ? ??? ?? ????.

//每頁顯示數(shù)
$num = 5;
$total = ceil($count / $num);

?? ???, ?? ??? ?? ??

? ????? ?? ???? ????, ??? ????? ?? ???? ???? ??? ????

? ?? ???? ??? ???? ???? ?? ? ???? ???? ????.

??? ??? ??? ??? ???? ???. ??? ??? ?? ? ?? ????? 1? ?? ?? ? ?? ???? ????.
??? ???? ??? ???? ??? ???? ??? ????? ?????.

if ($page <= 1) {
    $page = 1;
}
if ($page >= $total) {
    $page = $total;
}

2. SQL ?

?? ???? ??? ???? ??? ?? ? ???? ??? ???? ?????? ?????. SQL ? ??? ????.

?? ?? ??? ??????.

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

SQL ?? $num ? $offset? ??????.

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

Control URI? ??? ?

echo '<tr>
    <td colspan="5">
    <a href="page.php?page=1">首頁</a>
    <a href="page.php?page=' . ($page - 1) . '">上一頁</a>
    <a href="page.php?page=' . ($page + 1) . '">下一頁</a>
    <a href="page.php?page=' . $total . '">尾頁</a>
    當(dāng)前是第 ' . $page . '頁  共' . $total . '頁
    </td>
    </tr>';

??? ?? ????? ???? ?? ??? ????.

include 'connection.php';


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

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

$data = mysqli_fetch_assoc($result);

//得到總的用戶數(shù)
$count = $data['c'];

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

/*
if (isset($_GET['page'])) {
    $page = (int) $_GET['page'];
} else {
    $page = 1;
}
 */

//每頁顯示數(shù)

$num = 5;

//得到總頁數(shù)
$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)) {

    //存在數(shù)據(jù)則循環(huán)將數(shù)據(jù)顯示出來

    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">首頁</a>  <a href="page.php?page=' . ($page - 1) . '">上一頁</a>   <a href="page.php?page=' . ($page + 1) . '">下一頁</a>  <a href="page.php?page=' . $total . '">尾頁</a>  當(dāng)前是第 ' . $page . '頁  共' . $total . '頁 </td></tr>';

    echo '</table>';

} else {
    echo '沒有數(shù)據(jù)';
}

mysqli_close($conn);


???? ??
||
<?php $num = 5; $offset = ($page - 1) * $num; //我們將$num和$offset應(yīng)用于SQL語句中: $sql = "select id,username,createtime,createip from user order by id desc limit $offset , $num"; //控制好URI中的分頁值 echo '<tr> <td colspan="5"> <a href="page.php?page=1">首頁</a> <a href="page.php?page=' . ($page - 1) . '">上一頁</a> <a href="page.php?page=' . ($page + 1) . '">下一頁</a> <a href="page.php?page=' . $total . '">尾頁</a> 當(dāng)前是第 ' . $page . '頁 共' . $total . '頁 </td> </tr>'; //我們最后將整體業(yè)務(wù)串聯(lián)起來實現(xiàn)最終效果,代碼如下: include 'connection.php'; $count_sql = 'select count(id) as c from user'; $result = mysqli_query($conn, $count_sql); $data = mysqli_fetch_assoc($result); //得到總的用戶數(shù) $count = $data['c']; $page = isset($_GET['page']) ? (int) $_GET['page'] : 1; /* if (isset($_GET['page'])) { $page = (int) $_GET['page']; } else { $page = 1; } */ //每頁顯示數(shù) $num = 5; //得到總頁數(shù) $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)) { //存在數(shù)據(jù)則循環(huán)將數(shù)據(jù)顯示出來 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">首頁</a> <a href="page.php?page=' . ($page - 1) . '">上一頁</a> <a href="page.php?page=' . ($page + 1) . '">下一頁</a> <a href="page.php?page=' . $total . '">尾頁</a> 當(dāng)前是第 ' . $page . '頁 共' . $total . '頁 </td></tr>'; echo '</table>'; } else { echo '沒有數(shù)據(jù)'; } mysqli_close($conn); ?>