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

    1.引用封装类

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <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.php");
        include("page.class.php");
        
        //造对象
        $db = new DBDA();
        $sqlcount = "select count(*) from ChinaStates";
        $atrrc =  $db->Query($sqlcount);
        $total = $atrrc[0][0];
        
        //造分页对象
        $page = new page($total,15,"");
        
        $page->set('head','条数据');
        $page->set('prev',"<img src='0063.png' width='15' height='15' />");
        $page->set('frist','第一页');
        
        //显示
        $sql = "select * from ChinaStates ".$page->limit;
        echo $sql;
        $attr = $db->Query($sql);
        
        for($i=0;$i<count($attr);$i++)
        {
            echo "<tr><td>{$attr[$i][0]}</td><td>{$attr[$i][1]}</td><td>{$attr[$i][2]}</td></tr>";
        }
        
    ?>
    </table>
    <?php
        echo $page->fpage();
    ?>
    </body>
    </html>

    2.查询

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    
    <div>
        <form action="Test.php" method="post">
        <div>
            名称:
            <input type="text" name="name" />
            价格:
            <input type="text" name="price" />
            <input type="submit" value="查询" />
        </div>
        </form>
    </div>
    <br />
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>代号</td>
        <td>名称</td>
        <td>价格</td>
    </tr>
    <?php
        
        include("DBDA.php");
        $db = new DBDA();
        
        /*$str = "";
        if(!empty($_POST["name"]))
        {
            $name = $_POST["name"];
            $price = $_POST["price"];
            
            $str ="";
            
            $str = "where";
            $tj1 = "";
            if($name !="")
            {
                $tj1 = " Name like '%{$name}%'";
            }
            else
            {
                $tj1 =" 1=1";
            }
            if($price !="")
            {
                $tj2 = "price ='{$price}'";
            }
            else
            {
                $tj2 ="1=1";
            }
            $str = "where".$tj1." and ".$tj2;
            
        }*/
        
            @$name = $_POST["name"];
            @$price = $_POST["price"];
            
            $str ="";
            
            //查询
            $tj1 = " 1=1";
            $tj2 = " 1=1";
            if($name !="")
            {
                $tj1 = " Name like '%{$name}%'";
            }
            
            if($price !="")
            {
                $tj2 = "price ={$price}";
            }
            $str = " where".$tj1." and ".$tj2;
        
        //写SQL语句
        $sql = "select Code,Name,Price from Car".$str;
        
        echo $sql;
        //调用里面的query方法执行SQL语句
        $attr = $db->Query($sql);
        
        for($i=0;$i<count($attr);$i++)
        {
            //关键字变色处理
            $mc = str_replace($name,"<mark><span style= 'color:red'>{$name}</span></mark>>",$attr[$i][1]);
            //$attr[$i][0];
            echo "<tr><td>{$attr[$i][0]}</td><td>{$mc}</td><td>{$attr[$i][2]}</td></tr>";
        }
        
        
        
        
        
        
        
    
    
    ?>
    </table>
    </body>
    </html>

    查询关键字变色处理

  • 相关阅读:
    Centos7如何安装开源办公软件Libreoffice
    vi/vim输入中文乱码,无法输入中文解决方法
    NFS+Rsync增量备份方案
    完全备份,增量备份,差异备份及恢复区别
    Centos7安装Windows程序,例如QQ,微信,notepad++等exe程序
    Centos7升级内核后,导致打开VMware提示需要安装vmmon和vmnet模块
    SSH安全加固
    PHP使用mail函数发送邮件
    Centos7使用mail命令发送邮件
    Python部署配置Django架构教程
  • 原文地址:https://www.cnblogs.com/Yue0327/p/5338805.html
Copyright © 2011-2022 走看看