zoukankan      html  css  js  c++  java
  • 利用封装类查询

    <!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="0271.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" cellpadding="0">
    <tr>
    <td>代号</td>
    <td>名称</td>
    <td>价格</td>
    </tr>
    <?php
    include("027/test.php");
    $db=new DBDA();
    //单条件查询
    /*if(!empty($_POST["name"])
    {
        $name=$_POST["name"];
        if($name !="")
        {
            
        $str=$str." where Name like '%{$name}%'";    
        }
    }
    */
    //多条件查询
    @$name = $_POST["name"];
        @$price = $_POST["price"];
        
        $tj1 = " 1=1";
        $tj2 = " 1=1";
        if($name != "")
        {
            $tj1 = " Name like '%{$name}%'";
        }
    
        if($price != "")
        {
            $tj2 = " Price like '%{$price}.%'";
        }
    
        
        $str = " where".$tj1." and ".$tj2;
        
            
    
    $sql="select Code,Name,Price from Car".$str;
    echo $sql;
    $attr=$db->Query($sql);
    
    for($i=0;$i<count($attr);$i++)
    {
        //关键字变色处理
    $zw=str_replace($name,"<mark>{$name}</mark>",$attr[$i][1]);
        echo "<tr><td>{$attr[$i][0]}</td><td>{$zw}</td><td>{$attr[$i][2]}</td></tr>";
        
    }
    
    
    
    
    
    ?>
    </table>
    </body>
    </html>
  • 相关阅读:
    可视化数据库管理工具DataGrip使用详解
    MySQL常用函数
    你必须掌握的 21 个 JAVA 核心技术!
    idea中那些好用到飞起的插件
    Object使用
    单页面应用和多页面应用的区别及优缺点
    正则常用匹配
    npm --save-dev 和 --save 的区别
    js常用小技巧
    js复制文字到剪切板
  • 原文地址:https://www.cnblogs.com/crazy-zw/p/5326139.html
Copyright © 2011-2022 走看看