色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php分頁代碼學習示例分享

復制代碼 代碼如下:
<?php 
    header("content-type:text/html;charset=utf-8");
    //數(shù)據(jù)庫連接
    $conn = mysql_connect("localhost", "root", "111") or die("not connnected : ".mysql_error());
    mysql_select_db("test", $conn);
    mysql_query("set names utf8");

    //查詢共有多少行數(shù)據(jù)
    $sql1 = "select count(*) from user";
    $ret1 = mysql_query($sql1);
    $row1 = mysql_fetch_row($ret1);
    $tot = $row1[0];

    //每頁多少行數(shù)據(jù)
    $length = 5;     
    //總頁數(shù) 
    $totpage = ceil($tot / $length);

    //當前頁數(shù)
    $page = @$_GET['p'] ? $_GET['p'] : 1;
    //limit 下限
    $offset = ($page - 1) * $length;

    echo "<center>";
    echo "<h2>php padding</h2>";
    echo "<table width='700px' border='1px' >";
    echo "<tr>";
    echo "<th>ID</th>";
    echo "<th>USER</th>";
    echo "<th>PASS</th>";
    echo "</tr>";

    //將查詢出來的數(shù)據(jù)用表格顯示
    $sql2 = "select * from user order by id limit {$offset}, {$length}";
    $ret2 = mysql_query($sql2);
    while ($row2 = mysql_fetch_assoc($ret2)) {
        echo "<tr>";
        echo "<td>{$row2['id']}</td><td>{$row2['name']}</td><td>{$row2['pass']}</td>";
        echo "</tr>";
    }

    echo "</table>";

    //和
    $prevpage = $page - 1;
    if ($page >= $totpage) {
        $nextpage = $totpage;
    } else {
        $nextpage = $page + 1;
    }

    //跳轉
    echo "<h3><a href='index.php?p={$prevpage}'></a>|<a href='index.php?p={$nextpage}'></a></h3>";
    echo "</center>";

核心點:

<1>“$sql2 = "select * from user order by id limit {$offset}, {$length}";”,$offset、$length和頁數(shù)之間的關系。

<2>和的獲得方式,以及臨界點。

 

php技術php分頁代碼學習示例分享,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 赤水市| 临海市| 西畴县| 贵南县| 石景山区| 农安县| 兴文县| 长垣县| 澳门| 高碑店市| 高密市| 普兰县| 万载县| 镇平县| 平安县| 无极县| 南宫市| 集安市| 中阳县| 呈贡县| 攀枝花市| 重庆市| 三门县| 左云县| 攀枝花市| 原阳县| 崇信县| 咸阳市| 富锦市| 苏尼特左旗| 富阳市| 巴青县| 赤城县| 望都县| 哈尔滨市| 嘉荫县| 搜索| 恩施市| 玉林市| 富民县| 宝清县|