• mysqli数据查询


    <!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>
    <h1>查询数据</h1>
    <form action="biaoge.php" method="post">
    
    <div>请输入汽车名称:<input type="text" name="name" />
    <input type="submit" value="查询" />
    </div>
    <br />
    </form>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
    	<td>代号</td>
        <td>名称</td>
        <td>系列</td>
        <td>油耗</td>
        <td>价格</td>
        </tr>
        <?php
    	$tj = " 1=1 ";//做了一个恒成立的条件
    	$name = "";
    	if(!empty($_POST)){
    		$name = $_POST["name"];
    		$tj = " name like '%{$name}%'";
    		}
    		
    	$db=new MySQLi("localhost","root","123","ceshi");
    	$sql = "select * from  car where {$tj}";
    	echo $sql;
    	$relsut=$db->query($sql);
    	if($relsut){
    		$arr = $relsut->fetch_all();
    		foreach($arr as $v){
    			$v[1];$name;
    			$carname = str_replace($name,"<mark>{$name}</mark>",$v[1]);
    			echo "<tr>
    	<td>{$v[0]}</td>
        <td>{$carname}</td>
        <td>{$v[2]}</td>
        <td>{$v[4]}</td>
        <td>{$v[7]}</td>
        </tr>";
    			}
    		}
    	?>
    </table>
    
    </body>
    </html>
    

     

    多条件查询

    <!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>
    <h1>查询数据</h1>
    <form action="duogechaxun.php" method="post">
    <div>请输入汽车名称:<input type="text" name="name" />
    请输入系列代号:<input type="text" name="brand" />  
    <input type="submit" value="查询" /></div>
    <br />
    </form>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
    	<td>代号</td>
        <td>名称</td>
        <td>系列</td>
        <td>油耗</td>
        <td>价格</td>
        </tr>
        <?php
    	$tj = " 1=1 ";//做了一个恒成立的条件
    	$tj2 = " 1=1 ";
    	$name = "";
    	if(!empty($_POST["name"])){
    		$name = $_POST["name"];
    		$tj = " name like '%{$name}%' ";
    		}
    	if(!empty($_POST["brand"])){
    		$brand = $_POST["brand"];
    		$tj2 = " brand = '{$brand}' ";
    		}
    			
    		
    	$db=new MySQLi("localhost","root","123","ceshi");
    	$sql = "select * from  car where {$tj} and {$tj2}";
    	echo $sql;
    	$relsut=$db->query($sql);
    	if($relsut){
    		$arr = $relsut->fetch_all();
    		foreach($arr as $v){
    		
    			
    			echo "<tr>
    	<td>{$v[0]}</td>
        <td>{$v[1]}</td>
        <td>{$v[2]}</td>
        <td>{$v[4]}</td>
        <td>{$v[7]}</td>
        </tr>";
    			}
    		}
    	?>
    </table>
    
    </body>
    </html>
    

      

  • 相关阅读:
    《当程序员的那些狗日日子》(二十六)再下决心
    创建本地数据库
    Servlet的开发和使用
    tomcat7不能创建解决办法
    windows系统纯净版下载
    Linux打包命令
    Filter的开发和使用
    C语言地址传递和值传递简析
    Servlet生命周期
    Java EE架构
  • 原文地址:https://www.cnblogs.com/xiaohaihuaihuai/p/8324386.html
Copyright © 2020-2023  润新知