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

php分頁代碼學習示例分享

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

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

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

    //當前頁數
    $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>";

    //將查詢出來的數據用表格顯示
    $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和頁數之間的關系。

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

 

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

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

主站蜘蛛池模板: 永新县| 萝北县| 吉首市| 岳池县| 定边县| 仙居县| 额敏县| 九龙县| 彭山县| 南乐县| 扬中市| 高淳县| 富蕴县| 梁平县| 福清市| 綦江县| 石景山区| 崇文区| 扶风县| 闵行区| 贺州市| 巴里| 开鲁县| 儋州市| 仙桃市| 尉氏县| 湘阴县| 莱州市| 玉环县| 淳化县| 美姑县| 凤凰县| 白银市| 阳城县| 湘潭县| 任丘市| 年辖:市辖区| 邢台县| 阜南县| 南投县| 渭源县|