题目:

示例图

本次只做图4这个表,因为之前的都已做过

自己在mydb数据库建了一个house表

如图:

自己做的代码:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>无标题文档</title>
  6. </head>
  7.  
  8. <body>
  9. <form  action="house_main.php" method="post">
  10. <div>
  11. 区域:
  12.     <input type="checkbox" name="qx1" onclick="checkall(this)" />全选
  13. </div>
  14. <div>    
  15.     
  16.  
  17.     <?php
  18.         $db = new MySQLi("localhost","root","root","mydb");
  19.         $sqlqx = "select distinct area from house ";
  20.         
  21.         $resultqx = $db->query($sqlqx);
  22.         while($arrqx = $resultqx->fetch_row())
  23.         {
  24.             
  25.             echo"<input class='qx' type='checkbox' value='{$arrqx[0]}' name='qx[]' />{$arrqx[0]}";
  26.         }
  27.         
  28.     ?>
  29. </div>
  30. <div>
  31. 租赁类型:
  32.     <input type="checkbox" name="qx2" onclick="checkall2(this)"/>全选
  33. </div>
  34. <div>
  35.     <?php
  36.         
  37.         $sqlqy = "select distinct renttype from house ";
  38.         
  39.         $resultqy = $db->query($sqlqy);
  40.         while($arrqy = $resultqy->fetch_row())
  41.         {
  42.             
  43.             echo"<input class='qy' type='checkbox' value='{$arrqy[0]}' name='qy[]'/>{$arrqy[0]}";
  44.         }
  45.     ?>
  46.  
  47. </div>
  48.  
  49. <div>
  50. 房屋类型:
  51.     <input type="checkbox" name="qx3" onclick="checkall3(this)"/>全选
  52. </div>
  53. <div>
  54.     <?php
  55.         
  56.         $sqlqz = "select distinct housetype from house";
  57.         
  58.         $resultqz = $db->query($sqlqz);
  59.         while($arrqz = $resultqz->fetch_row())
  60.         {
  61.             
  62.             echo"<input class='qz' type='checkbox' value='{$arrqz[0]}' name='qz[]' />{$arrqz[0]}";
  63.         }
  64.     ?>
  65. </div>
  66.  
  67. <div>
  68. 关键字:
  69. <input  type="text" name="keyword"/>
  70. </form>
  71. <br />
  72.  
  73. <input type="submit" value="搜索" />
  74. </div>
  75.  
  76. </div>
  77. <br />
  78. <br />
  79. <br />
  80.  
  81. </form>
  82. <table width="50%" border="1" cellpadding="0" cellspacing="0">
  83.     <tr>
  84.         <td>关键字</td>
  85.         <td>区域</td>
  86.         <td>建筑面积</td>
  87.         <td>租金</td>
  88.         <td>租赁类型</td>
  89.         <td>房屋类型</td>
  90.     </tr>
  91.     <?php
  92.         $tj = "";
  93.         $tj1 = "1=1";
  94.         $tj2 = "2=2";
  95.         $tj3 = "3=3";
  96.         $tj4 = "4=4";
  97.         if(!empty($_POST["qx"]) && count($_POST["qx"]>0))
  98.         {
  99.             $attr = $_POST["qx"];
  100.             $str = implode("','",$attr);
  101.  
  102.             $tj1 = "area in ('{$str}')";    
  103.         }
  104.         if(!empty($_POST["qy"]) && count($_POST["qy"]>0))
  105.         {
  106.             $attr = $_POST["qy"];
  107.             $str = implode("','",$attr);
  108.             
  109.             $tj2 = "renttype in ('{$str}')";
  110.         }
  111.         if(!empty($_POST["qz"]) && count($_POST["qz"]>0))
  112.         {
  113.             $attr = $_POST["qz"];
  114.             $str = implode("','",$attr);
  115.  
  116.             $tj3 = "housetype in ('{$str}')";
  117.         }
  118.         if(!empty($_POST["keyword"]) && count($_POST["keyword"]>0))
  119.         {
  120.             $attr = $_POST["keyword"];
  121.             $tj4 = "keyword like '%{$attr}%'";    
  122.         }
  123.         //$tj = " where {$tj1} and {$tj2} and {$tj3} and {$tj4} ";
  124.         $sql = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4} ";
  125.         $attry = $db->query($sql);
  126.         while($arr = $attry->fetch_row())
  127.         {
  128.             echo"<tr>
  129.             <td>{$arr[1]}</td>
  130.             <td>{$arr[2]}</td>
  131.             <td>{$arr[3]}</td>
  132.             <td>{$arr[4]}</td>
  133.             <td>{$arr[5]}</td>
  134.             <td>{$arr[6]}</td>
  135.             </tr>";
  136.         }
  137.     
  138.     ?>
  139.  
  140. </table>
  141. </body>
  142. </html>
  143. <script type="text/javascript">
  144.  
  145. function checkall(qx)
  146. {    //ck变量不能重复设置
  147.     var ck = document.getElementsByClassName("qx");
  148.     
  149.     if(qx.checked)
  150.     {
  151.         for(var i=0;i<ck.length;i++)
  152.         {
  153.             ck[i].setAttribute("checked","checked");
  154.         }
  155.     }
  156.     else
  157.     {
  158.         for(var i=0;i<ck.length;i++)
  159.         {
  160.             ck[i].removeAttribute("checked");
  161.         }
  162.     }
  163. }
  164. function checkall2(qy)
  165. {
  166.     var ck2 = document.getElementsByClassName("qy");
  167.     
  168.     if(qy.checked)
  169.     {
  170.         for(var i=0;i<ck2.length;i++)
  171.         {
  172.             ck2[i].setAttribute("checked","checked");
  173.         }
  174.     }
  175.     else
  176.     {
  177.         for(var i=0;i<ck2.length;i++)
  178.         {
  179.             ck2[i].removeAttribute("checked");
  180.         }
  181.     }
  182. }
  183. function checkall3(qz)
  184. {
  185.     var ck3 = document.getElementsByClassName("qz");
  186.     
  187.     if(qz.checked)
  188.     {
  189.         for(var i=0;i<ck3.length;i++)
  190.         {
  191.             ck3[i].setAttribute("checked","checked");
  192.         }
  193.     }
  194.     else
  195.     {
  196.         for(var i=0;i<ck3.length;i++)
  197.         {
  198.             ck3[i].removeAttribute("checked");
  199.         }
  200.     }
  201. }
  202. </script>

展示效果:

查询范例:

搜索结果如下:

php 数据库练习之租房子的更多相关文章

  1. 11月6日上午PHP练习《租房子》解析

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  2. PHP-----练习-------租房子-----增删改查,多条件查询

    练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...

  3. PHP实例练习--投票和租房子

    一,调查问卷 效果图:

  4. php 租房子(练习题)

    一.题目要求 1.功能描述   出租房屋数据管理及搜索页面 2.具体要求 (1) 创建数据库HouseDB,创建表House,要求如下: 二.题目做法 1.建立数据库 2.封装类文件 <?php ...

  5. php练习 租房子

    题目要求 1.封装类 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming=&q ...

  6. 最近要租房子,用Python看一下房源吧..

    前言:最近我的朋友想要租房子,为了装个b,决定运用技术去帮助他. 这个网站是什么我也不知道 反正是一个房子交易网站  http://www.ljia.net/ 设置请求头 headers = {'Ac ...

  7. PHP 练习(租房子)

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  8. PHP 练习3:租房子

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  9. php封装+租房子练习题

    第一个页面DBDA.class.php <?php class DBDA { public $host = "localhost"; public $uid = " ...

随机推荐

  1. C语言 · 芯片测试

    基础练习 芯片测试   时间限制:1.0s   内存限制:512.0MB    问题描述 有n(2≤n≤20)块芯片,有好有坏,已知好芯片比坏芯片多. 每个芯片都能用来测试其他芯片.用好芯片测试其他芯 ...

  2. git 远程仓库版本的回退以及git reset 几种常用方式记录

    由于 github push 了两个比较潦草的commit, 自己很不满意,又不想重新开vpn进行上传,所以找了一下相关的教程. 最后研究了一下,原理为先在本地还原到你想要的commit,然后强制pu ...

  3. stm8s + si4463 寄存器配置

    /***********************************************函 数: main功 能: 程序入口输 入: /输 出: /描 述: /**************** ...

  4. CKFinder 弹出窗口操作并设置回调函数

    CKFinder 弹出窗口操作并设置回调函数 官方例子参考CKFinderJava-2.4.1/ckfinder/_samples/popup.html 写一个与EXT集成的小例子 Ext.defin ...

  5. Apache HttpComponents POST提交带参数提交

    public class Test { public static void main(String[] args) throws IOException { DefaultHttpClient ht ...

  6. uboot中变量env(收集)

    Env在u-boot中通常有两种存在方式,在永久性存储介质中(flash.NVRAM等),在SDRAM中.可配置不适用env的永久存储方式,但不常用.U-boot在启动时会将存储在永久性存储介质中的e ...

  7. javascript那些不应该忽视的细节

    1.null与Object.prototype使用typeof操作符结果都是object,但他们都不是Object的实例. typeof null // object null instanceof ...

  8. C++实现 逆波兰表达式计算问题

    C++实现 逆波兰表达式计算问题 #include <iostream> #include <string> using namespace std; class Stack ...

  9. Entity Framework开发介绍

    一.Entity Framework概要 Entity Framework是微软的Object Relational Mapper(对象关系映射),也就是我们平常说的ORM,它可以让应用程序开发者将关 ...

  10. sparkr基本操作1

    由于装的sparkr是1.4版本的,老版本的很多函数已经不再适用了. 在2台服务器的组成的集群中测试了一版数据,熟悉下这个api的基本操作.​ libpath <- .libPaths() li ...