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>
    <?php
         include("DBDA.class.php");
    		 $db=new DBDA();
    		 
    		 $cx="";
    		 $value="";
    		 
    		 $tj1="1=1";//条件1的判断
    		 $tj2="1=1";//条件2的判断
    		 
    		 if(!empty($_POST["name"]))
    		 {
    			 $name=$_POST["name"];
    			 $tj1="name like '%{$name}%'";
    			 $value=$name;
    		 }
    		 if(!empty($_POST["brand"]))
    		 {
    			 $tj2="brand='{$_POST['brand']}'";
    		 }
    		 $cx=" where {$tj1} and {$tj2}";
    		
    ?>
    <h1>汽车查询页面</h1><br />
    <form action="test-duo.php" method="post">
    <div>
        请输入名称:<input type="text" name="name" value="<?php echo $value;?>"/> 
        系列:<input type="text" name="brand"/> 
        <input type="submit" value="查询"/>
    </div></form>
    <br />
    
    <table width="1000px" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td>代号</td>
            <td>汽车名称</td>
            <td>系列</td>
            <td>价格</td>
            <td>油耗</td>
            <td>功率</td>
        </tr>
        
        <?php
    	     
    		 
    		 
    		 $sql="select * from car".$cx;
    		 $attr=$db->Query($sql);
    		 
    		 foreach($attr as $v)
    		 {
    			 //处理name
    			 $rp="<span style='color:red'>{$value}</span>";
    			 $str=str_replace($value,$rp,$v[1]);
    			 echo "<tr>
    			         <td>{$v[0]}</td>
    					 <td>{$str}</td>
    					 <td>{$v[2]}</td>
    					 <td>{$v[7]}</td>
    					 <td>{$v[4]}</td>
    					 <td>{$v[5]}</td>
    			       </tr>";
    		 }
    	
        ?>
    </table>
    </body>
    </html>
    

      多条件查询主页面显示

    多条件查询结果显示页面

  • 相关阅读:
    继承
    反射
    DOS使用笔记
    [LeetCode] Merge Intervals
    [LeetCode] Insert Interval
    [LeetCode] Permutation Sequence
    [LeetCode] Rotate List
    [LeetCode] Text Justification
    [LeetCode] Simplify Path(可以不用看)
    [LeetCode] Edit Distance(很好的DP)
  • 原文地址:https://www.cnblogs.com/zst062102/p/5469423.html
Copyright © 2011-2022 走看看