php實現出租房資料管理及搜尋網頁面

來源:互聯網
上載者:User
這篇文章主要為大家詳細介紹了php出租房資料管理及搜尋網頁面的相關資料,具有一定的參考價值,感興趣的小夥伴們可以參考一下

php資料訪問例子:租房資訊管理,具體內容如下

1.資料庫建表

2. zufangzi.php


<body><h1>租房子</h1><form action="zufangzi.php" method="post"><p>地區:<input type="checkbox" name="qx" onclick="quanxuan(this,'qy')" />全選</p><p><?phprequire "DBDA.class1.php";$db = new DBDA();$sqy = "select distinct area from house";//寫SQL語句,並去重$aqy = $db->query($sqy);foreach($aqy as $v){  echo "<input type='checkbox' name='qy[]' value='{$v[0]}' class='qy' />{$v[0]}";}?></p><br /><p>租賃類型:<input type="checkbox" name="zlqx" onclick="quanxuan(this,'zl')" />全選</p><p><?php$szl = "select distinct renttype from house";$azl = $db->query($szl);foreach($azl as $v){  echo "<input type='checkbox' name='zl[]' value='{$v[0]}' class='zl' />{$v[0]}";}?></p><br /><p>房屋類型:<input type="checkbox" name="fwqx" onclick="quanxuan(this,'fw')" />全選</p><p><?php$sfw = "select distinct housetype from house";$afw = $db->query($sfw);foreach($afw as $v){  echo "<input type='checkbox' name='fw[]' value='{$v[0]}' class='fw' />{$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("','",$aqy);        $tj1 = " area in ('{$sqy}') ";  }    if(!empty($_POST["zl"]))  {    $azl = $_POST["zl"];    $szl = implode("','",$azl);        $tj2 = " renttype in ('{$szl}') ";  }    if(!empty($_POST["fw"]))  {    $afw = $_POST["fw"];    $sfw = implode("','",$afw);        $tj3 = " housetype in ('{$sfw}') ";  }    if(!empty($_POST["key"]))  {    $k = $_POST["key"];    $tj4 = " keyword like '%{$k}%' ";  }      $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>

所引用的封裝類

<?phpclass 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;    }  }}

呈現頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.