php多条件查询
需要查询的表格
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | <!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 require "Wang.class.php" ; //调用类 $db = new Wang(); $keyword = "" ; $tj1 = " 1=1 " ; $tj2 = " 1=1 " ; $tj3 = " 1=1 " ; $tj4 = " 1=1 " ; if (! empty ( $_POST [ "area" ])) { $area = $_POST [ "area" ]; $str1 = implode( "','" , $area ); $tj1 = " area in ('{$str1}') " ; } if (! empty ( $_POST [ "renttype" ])) { $renttype = $_POST [ "renttype" ]; $str2 = implode( "','" , $renttype ); $tj2 = " renttype in ('{$str2}') " ; } if (! empty ( $_POST [ "housetype" ])) { $housetype = $_POST [ "housetype" ]; $str3 = implode( "','" , $housetype ); $tj3 = " housetype in ('{$str3}') " ; } if (! empty ( $_POST [ "keyword" ])) { $keyword = $_POST [ "keyword" ]; $tj4 = " keyword like '%{$keyword}%' " ; } ?> <form action= "Fchaxun.php" method= "post" > <div> 区 域:<input type= "checkbox" onclick= "quanxuan(this,'qy')" />全选 </div> <div> <?php $sql = "select distinct area from house" ; $arr = $db ->query( $sql ); foreach ( $arr as $v ) { echo "<td><input type='checkbox' name='area[]' value='{$v[0]}' class='qy'/>{$v[0]} </td>" ; } ?> </div> <br /> <div> 租赁类型: <input type= "checkbox" onclick= "quanxuan(this,'zp')" />全选 </div> <div> <?php $sqlr = "select distinct renttype from house" ; $arr1 = $db ->query( $sqlr ); foreach ( $arr1 as $r ) { echo "<td><input type='checkbox' name='renttype[]' value='{$r[0]}' class='zp'/>{$r[0]}</td>" ; } ?> </div> <br /> <div> 房屋类型:<input type= "checkbox" onclick= "quanxuan(this,'fw')" />全选 </div> <div> <?php $sqlh = "select distinct housetype from house" ; $arr2 = $db ->query( $sqlh ); foreach ( $arr2 as $h ) { echo "<td><input type='checkbox' name='housetype[]' value='{$h[0]}' class='fw'/>{$h[0]}</td>" ; } ?> </div> <br /> <div> 关 键 字: <input type= "text" name= "keyword" value= "<?php echo $keyword ?>" /> </div> <div><input type= "submit" value= "搜索" /></div> </form> </br> <table border= "1" > <tr> <!--<td>标识</td>--> <td>关键字</td> <td>区域</td> <td>面积</td> <td>租金(每月)</td> <td>租赁类型</td> <td>房屋类型</td> </tr> <?php $tj = " {$tj1} and {$tj2} and {$tj3} and {$tj4} " ; $sqly = "select * from house where " . $tj ; $arry = $db ->query( $sqly ,1); foreach ( $arry as $y ) { $str = str_replace ( $keyword , "<span style='color:red'>{$keyword}</span>" , $y [1]); echo "<tr> <td>{ $str }</td> <td>{ $y [2]}</td> <td>{ $y [3]}</td> <td>{ $y [4]}</td> <td>{ $y [5]}</td> <td>{ $y [6]}</td> </tr>"; } ?> </table> </body> </html> <script type= "text/javascript" > function quanxuan(a,qy) { var ck = document.getElementsByClassName(qy); if (a.checked) { for ( var i=0;i<ck.length;i++) { ck[i].setAttribute( "checked" , "checked" ); } } else { for ( var i=0;i<ck.length;i++) { ck[i].removeAttribute( "checked" ); } } } </script> |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 【译】我们最喜欢的2024年的 Visual Studio 新功能
· 个人数据保全计划:从印象笔记迁移到joplin
· Vue3.5常用特性整理
· 重拾 SSH:从基础到安全加固
· 为什么UNIX使用init进程启动其他进程?