• MYSQLi数据访问查询数据


    单条件查询

    <body>
    	<div align="center" style="90%;">
        <h1>数据查询</h1>
        <form method="post" action="test-1.php">
        <div>请输入汽车品牌:<input type="text" name="name"/></div>
        <br />
        <div><input type="submit" value="查询" name="chaxun"/></div>
        <br />
        </form>
        <div>
        	<table width="90%" border="1" align="center" style="text-align:center;">
            	<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","123456","crud");
    		$sql = "select * from car where {$tj}";
    		$result = $db->query($sql);
    		if($result){
    			$arr = $result->fetch_all();
    			foreach($arr as $v){
    				$v[1];$name;
    				$carname = str_replace($name,"<font color='#FF0000'>{$name}</font>",$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>
        </div>
        </div>
    </body>
    

     

     多条件查询

    <body>
    	<div align="center" style="90%;">
        <h1>数据查询</h1>
        <form method="post" action="test-1.php">
        <div>请输入汽车品牌:<input type="text" name="name"/>  
        请输入系列代号:<input type="text" name="brand"/></div> <!--两个条件-->
        <br />
        <div><input type="submit" value="查询" name="chaxun"/></div>
        <br />
        </form>
        <div>
        	<table width="90%" border="1" align="center" style="text-align:center;">
            	<tr>
                	<td>汽车代号</td>
                    <td>汽车名字</td>
                    <td>系列代号</td>
                    <td>汽车油耗</td>
                    <td>汽车价格</td>
                </tr>
    	<?php 
    		$tj = " 1=1 ";//恒成立条件
    		$tj1 = " 1=1 ";//恒成立条件
    		$name = "";
    		$brand = "";
    		if(!empty($_POST["name"])){
    			$name = $_POST["name"];
    			$tj = " name like '%{$name}%' " ;
    		}
    		if(!empty($_POST["brand"])){
    			$brand = $_POST["brand"];
    			$tj1 = " brand = '{$brand}' " ;
    		}
        	$db = new MySQLi("localhost","root","123456","crud");
    		$sql = "select * from car where {$tj} and {$tj1}";
    		$result = $db->query($sql);
    		if($result){
    			$arr = $result->fetch_all();
    			if(!empty($arr)){
    				echo "数据不存在!";
    			}else{
    				foreach($arr as $v){
    				$v[1];$name;
    				$v[2];$brand;
    				$carname = str_replace($name,"<font color='#FF0000'>{$name}</font>",$v[1]);//字符串替换
    				$carbrand = str_replace($brand,"<font color='#FF0000'>{$brand}</font>",$v[2]);
    				echo"<tr>
    			<td>{$v[0]}</td>
    			<td>{$carname}</td>
    			<td>{$carbrand}</td>
    			<td>{$v[4]}</td>
    			<td>{$v[7]}</td>	
    				</tr>";
    				}	
    			}
    		}
        ?>
            </table>
        </div>
        </div>
    </body>
    

     

  • 相关阅读:
    周末郑州程序员朋友技术交流中的PPT
    WCF并发连接数的问题
    郑州.Net技术人员的招聘信息
    在路上
    Windows8体验(1)安装
    挖掘0day打进不同学校
    记一次绕过宝塔防火墙的BC站渗透
    一次实战中对tp5网站getshell方式的测试
    一次从弱口令到getshell
    一次HW实战
  • 原文地址:https://www.cnblogs.com/navyouth/p/8301572.html
Copyright © 2020-2023  润新知