zoukankan      html  css  js  c++  java
  • 分页查询

    要求:根据条件进行查询,显示查询后的分页页面

    说明:

    1、根据条件查询到所有记录,在调用分页limit方法实现分页功能;

    2、浏览器默认get方式传值;用post方式传值,只有在点击查询按钮时可以实现效果,要先将post方式转为get方式,在判断;

    代码:

    get方式

    <body>
    <?php
    include ("../config/DBDA.php");
    include ("../config/page.class.php");
    $dx=new DBDA();
    $tj=" 1=1 ";
    $name="";
    //如果没有条件,就显示所有分页,如果有条件就根据条件查询,显示查询后的分页
    if(!empty($_GET["name"]) && $_GET["name"]!= "")
    {
        $tj=" AreaName like '%{$_GET['name']}%' ";
        $name=$_GET["name"];
    }
    $ztj="where".$tj;
    ?>
    <form action="main.php" method="get">
    <input type="text" name="name" value="<?php echo $name; ?>"/>
    <input type="submit" value="查询"/>
    </form>
    <table border="1" width="80%" cellpadding="0" cellspacing="0">
    <tr>
    <th>区域代号</th>
    <th>区域名称</th>
    <th>父级代号</th>
    </tr>
    <?php
    //查询总共多少条数据
    $sq="select count(*) from chinastates ".$ztj;
    $result=$dx->Query($sq);
    $total=$result[0][0];
    //造一个分页对象
    $page=new Page($total,20);
    //拼一个分页条件
    $sql="select * from chinastates ".$ztj.$page->limit;
    $attr=$dx->Query($sql);
    foreach($attr as $v)
    {
        echo "<tr>
        <td align='center'>{$v[0]}</td>
        <td align='center'>{$v[1]}</td>
        <td align='center'>{$v[2]}</td>
        </tr>";
        }
    ?>
    </table>
    <?php
    //显示分页信息
    echo $page->fpage();
    ?>

    post方式

    <body>
    <?php
    include ("../config/DBDA.php");
    include ("../config/page.class.php");
    $dx=new DBDA();
    $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"];
    }                                          //区别1
    $ztj="where".$tj;
    $posttj="name={$name}";
    ?>
    <form action="main2.php" method="post">
    <input type="text" name="name" value="<?php echo $name; ?>"/>
    <input type="submit" value="查询"/>
    </form>
    <table border="1" width="80%" cellpadding="0" cellspacing="0">
    <tr>
    <th>区域代号</th>
    <th>区域名称</th>
    <th>父级代号</th>
    </tr>
    <?php
    //查询总共多少条数据
    $sq="select count(*) from chinastates ".$ztj;
    $result=$dx->Query($sq);
    $total=$result[0][0];
    //造一个分页对象
    $page=new Page($total,20,$posttj);    //区别2
    //在分页中默认用get方式传值,用post方式传值需要将post转化为get方式;  
    //拼一个分页条件
    $sql="select * from chinastates ".$ztj.$page->limit;
    $attr=$dx->Query($sql);
    foreach($attr as $v)
    {
        echo "<tr>
        <td align='center'>{$v[0]}</td>
        <td align='center'>{$v[1]}</td>
        <td align='center'>{$v[2]}</td>
        </tr>";
        }
    ?>
    </table>
    <?php
    //显示分页信息
    echo $page->fpage();
    ?>
    </body>
  • 相关阅读:
    成功的两大法宝:自我管理与积累人脉
    CEO十五条法则 (是基于对CEO更加的关怀)
    百度李彦宏教你创业七大招!非常实用
    商业领袖摘下"帽子"才能炼成极致
    Alter index coalesce VS shrink space
    sort_area_size参数的一些表现
    Difference between parameter COMPATIBLE and OPTIMIZER_FEATURES_ENABLE
    Oracle常用的几个父栓
    Know more about RAC GES STATISTICS
    ORA07445 [SIGBUS] [Object specific hardware error]错误一例
  • 原文地址:https://www.cnblogs.com/jinshui/p/5750026.html
Copyright © 2011-2022 走看看