当前位置:Gxlcms > php框架 > php出租房数据管理及搜索页面

php出租房数据管理及搜索页面

时间:2021-07-01 10:21:17 帮助过:44人阅读

php数据访问例子:租房信息管理,具体内容如下

1.数据库建表

2. zufangzi.php

  1. <body>
  2. <h1>租房子</h1>
  3. <form action="zufangzi.php" method="post">
  4. <div>区域:<input type="checkbox" name="qx" onclick="quanxuan(this,'qy')" />全选</div>
  5. <div>
  6. <?php
  7. require "DBDA.class1.php";
  8. $db = new DBDA();
  9. $sqy = "select distinct area from house";//写SQL语句,并去重
  10. $aqy = $db->query($sqy);
  11. foreach($aqy as $v)
  12. {
  13. echo "<input type='checkbox' name='qy[]' value='{$v[0]}' class='qy' />{$v[0]}";
  14. }
  15. ?>
  16. </div>
  17. <br />
  18. <div>租赁类型:<input type="checkbox" name="zlqx" onclick="quanxuan(this,'zl')" />全选</div>
  19. <div>
  20. <?php
  21. $szl = "select distinct renttype from house";
  22. $azl = $db->query($szl);
  23. foreach($azl as $v)
  24. {
  25. echo "<input type='checkbox' name='zl[]' value='{$v[0]}' class='zl' />{$v[0]}";
  26. }
  27. ?>
  28. </div>
  29. <br />
  30. <div>房屋类型:<input type="checkbox" name="fwqx" onclick="quanxuan(this,'fw')" />全选</div>
  31. <div>
  32. <?php
  33. $sfw = "select distinct housetype from house";
  34. $afw = $db->query($sfw);
  35. foreach($afw as $v)
  36. {
  37. echo "<input type='checkbox' name='fw[]' value='{$v[0]}' class='fw' />{$v[0]}";
  38. }
  39. ?>
  40. </div>
  41. <br />
  42. <div>关键字:<input type="text" name="key" /> <input type="submit" value="查询" /></div>
  43. </form>
  44. <br />
  45. <table width="100%" border="1" cellpadding="0" cellspacing="0">
  46. <tr>
  47. <td>关键字</td>
  48. <td>区域</td>
  49. <td>建筑面积</td>
  50. <td>租金</td>
  51. <td>租赁类型</td>
  52. <td>房屋类型</td>
  53. </tr>
  54. <?php
  55. $tj1 = " 1=1 ";
  56. $tj2 = " 1=1 ";
  57. $tj3 = " 1=1 ";
  58. $tj4 = " 1=1 ";
  59. if(!empty($_POST["qy"]))
  60. {
  61. $aqy = $_POST["qy"];
  62. $sqy = implode("','",$aqy);
  63. $tj1 = " area in ('{$sqy}') ";
  64. }
  65. if(!empty($_POST["zl"]))
  66. {
  67. $azl = $_POST["zl"];
  68. $szl = implode("','",$azl);
  69. $tj2 = " renttype in ('{$szl}') ";
  70. }
  71. if(!empty($_POST["fw"]))
  72. {
  73. $afw = $_POST["fw"];
  74. $sfw = implode("','",$afw);
  75. $tj3 = " housetype in ('{$sfw}') ";
  76. }
  77. if(!empty($_POST["key"]))
  78. {
  79. $k = $_POST["key"];
  80. $tj4 = " keyword like '%{$k}%' ";
  81. }
  82. $sql = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
  83. echo $sql;
  84. $arr = $db->query($sql);
  85. foreach($arr as $v)
  86. {
  87. echo "<tr>
  88. <td>{$v[1]}</td>
  89. <td>{$v[2]}</td>
  90. <td>{$v[3]}</td>
  91. <td>{$v[4]}</td>
  92. <td>{$v[5]}</td>
  93. <td>{$v[6]}</td>
  94. </tr>";
  95. }
  96. ?>
  97. </table>
  98. </body>
  99. <script type="text/javascript">
  100. function quanxuan(qx,a)
  101. {
  102. //找到该全选按钮对应的checkbox列表
  103. var ck = document.getElementsByClassName(a);
  104. //找全选按钮选中状态
  105. if(qx.checked)
  106. {
  107. for(var i=0;i<ck.length;i++)
  108. {
  109. ck[i].setAttribute("checked","checked");
  110. }
  111. }
  112. else
  113. {
  114. for(var i=0;i<ck.length;i++)
  115. {
  116. ck[i].removeAttribute("checked");
  117. }
  118. }
  119. }
  120. </script>
  121. </html>

所引用的封装类

  1. <?php
  2. class DBDA
  3. {
  4. public $host = "localhost";
  5. public $uid = "root";
  6. public $pwd = "123";
  7. public $dbname = "test_123";
  8. //执行SQL语句返回相应的结果
  9. //$sql 要执行的SQL语句
  10. //$type 代表SQL语句的类型,0代表增删改,1代表查询
  11. function query($sql,$type=1)
  12. {
  13. $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
  14. $result = $db->query($sql);
  15. if($type)
  16. {
  17. //如果是查询,显示数据
  18. return $result->fetch_all();
  19. }
  20. else
  21. {
  22. //如果是增删改,返回true或者false
  23. return $result;
  24. }
  25. }
  26. }

呈现页面

 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

人气教程排行