码迷,mamicode.com
首页 > 其他好文 > 详细

0327

时间:2016-03-28 08:25:09      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

<!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();
    
    
    //查询
    @$name = $_POST["name"];
    @$price = $_POST["price"];
    
    $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,"<span style=‘color:red‘>{$name}</span>",$attr[$i][1]);
        
        echo "<tr><td>{$attr[$i][0]}</td><td>{$mc}</td><td>{$attr[$i][2]}</td></tr>";
    }
    
    
?>
</table>
</body>
</html>

 

0327

标签:

原文地址:http://www.cnblogs.com/zhuxiaolin/p/5327658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!