时间:2021-07-01 10:21:17 帮助过:18人阅读
单条件查询
<body> <div align="center" style="width: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>
MYSQLi数据访问查询数据
标签:log name mysql text 汽车 height select mysq where