首页 >后端开发 >php教程 >php实现出租房数据管理及搜索页面

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

墨辰丷
墨辰丷原创
2018-05-22 11:24:571607浏览

这篇文章主要为大家详细介绍了php出租房数据管理及搜索页面的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

1.数据库建表

2. zufangzi.php


<body>

<h1>租房子</h1>

<form action="zufangzi.php" method="post">
<p>区域:<input type="checkbox" name="qx" onclick="quanxuan(this,&#39;qy&#39;)" />全选</p>
<p>
<?php
require "DBDA.class1.php";
$db = new DBDA();

$sqy = "select distinct area from house";//写SQL语句,并去重
$aqy = $db->query($sqy);
foreach($aqy as $v)
{
  echo "<input type=&#39;checkbox&#39; name=&#39;qy[]&#39; value=&#39;{$v[0]}&#39; class=&#39;qy&#39; />{$v[0]}";
}
?>
</p>
<br />

<p>租赁类型:<input type="checkbox" name="zlqx" onclick="quanxuan(this,&#39;zl&#39;)" />全选</p>
<p>
<?php
$szl = "select distinct renttype from house";
$azl = $db->query($szl);
foreach($azl as $v)
{
  echo "<input type=&#39;checkbox&#39; name=&#39;zl[]&#39; value=&#39;{$v[0]}&#39; class=&#39;zl&#39; />{$v[0]}";
}
?>
</p>
<br />
<p>房屋类型:<input type="checkbox" name="fwqx" onclick="quanxuan(this,&#39;fw&#39;)" />全选</p>
<p>
<?php
$sfw = "select distinct housetype from house";
$afw = $db->query($sfw);
foreach($afw as $v)
{
  echo "<input type=&#39;checkbox&#39; name=&#39;fw[]&#39; value=&#39;{$v[0]}&#39; class=&#39;fw&#39; />{$v[0]}";
}
?>
</p>
<br />
<p>关键字:<input type="text" name="key" /> <input type="submit" value="查询" /></p>
</form>
<br />

<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td>关键字</td>
    <td>区域</td>
    <td>建筑面积</td>
    <td>租金</td>
    <td>租赁类型</td>
    <td>房屋类型</td>
  </tr>
  <?php
  
  $tj1 = " 1=1 ";
  $tj2 = " 1=1 ";
  $tj3 = " 1=1 ";
  $tj4 = " 1=1 ";
  
  if(!empty($_POST["qy"]))
  {
    $aqy = $_POST["qy"];
    $sqy = implode("&#39;,&#39;",$aqy);
    
    $tj1 = " area in (&#39;{$sqy}&#39;) ";
  }
  
  if(!empty($_POST["zl"]))
  {
    $azl = $_POST["zl"];
    $szl = implode("&#39;,&#39;",$azl);
    
    $tj2 = " renttype in (&#39;{$szl}&#39;) ";
  }
  
  if(!empty($_POST["fw"]))
  {
    $afw = $_POST["fw"];
    $sfw = implode("&#39;,&#39;",$afw);
    
    $tj3 = " housetype in (&#39;{$sfw}&#39;) ";
  }
  
  if(!empty($_POST["key"]))
  {
    $k = $_POST["key"];
    $tj4 = " keyword like &#39;%{$k}%&#39; ";
  }
  
  
  $sql = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";
  echo $sql;
  
  $arr = $db->query($sql);
  foreach($arr as $v)
  {
    echo "<tr>
    <td>{$v[1]}</td>
    <td>{$v[2]}</td>
    <td>{$v[3]}</td>
    <td>{$v[4]}</td>
    <td>{$v[5]}</td>
    <td>{$v[6]}</td>
  </tr>";
  }
  ?>
</table>

</body>
<script type="text/javascript">
function quanxuan(qx,a)
{
  //找到该全选按钮对应的checkbox列表
  var ck = document.getElementsByClassName(a);
  //找全选按钮选中状态
  if(qx.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>
</html>

所引用的封装类

<?php
class DBDA
{
  public $host = "localhost";
  public $uid = "root";
  public $pwd = "123";
  public $dbname = "test_123";
  //执行SQL语句返回相应的结果
  //$sql 要执行的SQL语句
  //$type 代表SQL语句的类型,0代表增删改,1代表查询
  function query($sql,$type=1)
  {
    $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
    
    $result = $db->query($sql);
    
    if($type)
    {
      //如果是查询,显示数据
      return $result->fetch_all();
    }
    else
    {
      //如果是增删改,返回true或者false
      return $result;
    }
  }
}

呈现页面

相关推荐:

使用纯HTML的通用数据管理和服务

微信小程序:新增数据管理 API 

详解SQL SERVER 2008 R2主数据管理

以上是php实现出租房数据管理及搜索页面的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn