• PHP分页查询


    分页
    导入page包,调用相应的方法
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
     
    <body>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>代号</td>
        <td>区域名称</td>
        <td>父级代号</td>
    </tr>
    <?php
    include ("DBDA.class.php");
    $db = new DBDA();
    include("Page.class.php");
     
    //求总条数
    $szong = "select count(*) from ChinaStates";
    $azong = $db->Query($szong);
    $zongshu = $azong[0][0]; //总条数
     
    //造分页对象
    $page = new Page($zongshu,15);
     
    //在SQL语句拼接分页条件
    $sql = "select * from ChinaStates ".$page->limit;
    $attr = $db->Query($sql);
     
    foreach($attr as $v)
    {
        echo "<tr>
        <td>{$v[0]}</td>
        <td>{$v[1]}</td>
        <td>{$v[3]}</td>
    </tr>";
    }
     
     
     //总共  页  5/100 当前  页 首页 上一页  1,2,3,4,5,6 下一页 尾页  跳转到  页
     
    ?>
    </table>
    <div>
    <?php
    //返回分页信息
    echo $page->fpage(4,5,6);
    ?>
    </div>
    </body>
    </html>
     
     
     
    分页加查询
    两种提交方式,get、post
        针对分页查询get相对简单,post略显复杂
    get提交
            form表单get提交到本页面
        $tj = " 1=1 ";
        $name="";
    if(!empty($_GET["name"]) && $_GET["name"]!=""){
        $tj = " AreaName like '%{$_GET['name']}%' ";
        $name=$_GET["name"];
    }
    $ztj = " where {$tj}";
     
    把条件变量    $ztj    拼接到sql语句后面
     
    post提交
        form表单post提交到本页面,首次可以,但是点列表时会刷新页面丢失post值
    $tj = " 1=1 ";
    $name="";
    if(!empty($_POST["name"]) && $_POST["name"]!="")
    {
        $tj = " AreaName like '%{$_POST['name']}%' ";
        $name=$_POST["name"];
    }
    if(!empty($_GET["name"]) && $_GET["name"]!="")
    {
        $tj = " AreaName like '%{$_GET['name']}%' ";
        $name=$_GET["name"];
    }
    $ztj = " where {$tj}";
    $posttj = "name={$name}";
     
    将总条件拼接到sql语句后面,然后在创建page对象是,初始化第三个参数$posttj ,将post值方式变为get值方式
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    Leetcode 剑指 Offer 27(二叉树的镜像)
    Leetcode 1022从根到叶的二进制之和
    Leetcode 993二叉树的堂兄弟节点
    Leetcode 965单值二叉树
    Leetcode 938 二叉搜索树的范围和
    hdu 2082 找单词
    母函数模板
    hdu 1398 Square Coins
    hdu 1085 Holding Bin-Laden Captive!
    hdu 1028 Ignatius and the Princess III
  • 原文地址:https://www.cnblogs.com/yongjiapei/p/5599005.html
Copyright © 2020-2023  润新知