租房子查询

1.发布房屋信息

  发布页面:

<!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>
<h1>发布新房</h1>
<table>
<form action="tianjiachuli.php" method="post">
<div>关键字:&nbsp;<input type="text" name="gjz" /></div>
<div>区域:&nbsp;&nbsp;<input type="text" name="qy" /></div>
<div>面积:&nbsp;&nbsp;<input type="text" name="mj" /></div>
<div>租金:&nbsp;&nbsp;<input type="text" name="zj" /></div>
<div>租赁类型:<input type="text" name="zllx" /></div>
<div>房屋类型:<input type="text" name="fwlx" /></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="插入" />
</form>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="chaxun.php"><input type="submit" value="取消" /></a>

</table>

</body>
</html>

  发布房屋信息处理页面代码:

<?php
$gjz = $_POST["gjz"];
$qy = $_POST["qy"];
$mj = $_POST["mj"];
$zj = $_POST["zj"];
$zllx = $_POST["zllx"];
$fwlx = $_POST["fwlx"];

$db = new MySQLi("localhost","root","212333","HouseDB");

$sql = "insert into house values(‘‘,‘{$gjz}‘,‘{$qy}‘,‘{$mj}‘,‘{$zj}‘,‘{$zllx}‘,‘{$fwlx}‘) ";

$r = $db->query($sql);

if($r)
{
    header("location:chaxun.php");
}
else
{
    echo "失败";
}

2.查看房屋信息

<!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>
</a><a href="sousuo.php"><input type="submit" value="搜索" /></a>
<form>
<div></div>
</form>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td></td>
        <td></td>
        <td>关键字</td>
        <td>区域</td>
        <td>使用面积</td>
        <td>租金</td>
        <td>租赁类型</td>
        <td>房屋类型</td>
    </tr>
    <?php
    $db = new MySQLi("localhost","root","212333","HouseDB");
    $sql = "select * from house";
    $result = $db->query($sql);
    $attr = $result->fetch_all();
    foreach($attr as $j)
    {
        echo "<tr>
                <td><a href=‘bianji.php?upt=$j[0]‘>编辑</a></td>
                <td><a href=‘shanchuchuli1.php?ass=$j[0]‘ onclick=\"return confirm(‘删除确认‘)\">删除</a></td>
                <td>$j[1]</td>
                <td>$j[2]</td>
                <td>$j[3]</td>
                <td>$j[4]</td>
                <td>$j[5]</td>
                <td>$j[6]</td>
             </tr>";
    }
    ?>
</table>
<div><a href="tianjia1.php"><input type="submit" value="添加数据" /></div>

</body>
</html>

3.删除和编辑处理页面

  编辑页面:

<!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
$upt = $_GET["upt"];

$db = new MySQLi("localhost","root","212333","HouseDB");

$sql = "select * from house where id=‘{$upt}‘";

$rrr = $db->query($sql);

$attr = $rrr->fetch_all();

foreach($attr as $v)
?>

<h1>编辑</h1>
<table>
<form action="bianjichuli.php" method="post">
<input type="hidden" name="id" value="<?php echo $v[0] ?>" />
<div>关键字:<input type="text" name="gjz" value="<?php echo $v[1] ?>" /></div>
<div>区域:<input type="text" name="qy" value="<?php echo $v[2] ?>" /></div>
<div>面积:<input type="text" name="mj" value="<?php echo $v[3] ?>" /></div>
<div>租金:<input type="text" name="zj" value="<?php echo $v[4] ?>" /></div>
<div>租赁类型:<input type="text" name="zllx" value="<?php echo $v[5] ?>" /></div>
<div>房屋类型:<input type="text" name="fwlx" value="<?php echo $v[6] ?>" /></div>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="更新" />
</form>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="chaxun.php"><input type="submit" value="取消" /></a>

</table>

</body>
</html>

  编辑处理页面代码:

<?php
$id = $_POST["id"];
$gjz = $_POST["gjz"];
$qy = $_POST["qy"];
$mj = $_POST["mj"];
$zj = $_POST["zj"];
$zllx = $_POST["zllx"];
$fwlx = $_POST["fwlx"];

$db = new MySQLi("localhost","root","212333","HouseDB");

$sql = "update house set KeyWord=‘{$gjz}‘,Area=‘{$qy}‘,SquareMeter=‘{$mj}‘,Rent=‘{$zj}‘,RentType=‘{$zllx}‘,HouseType
=‘{$fwlx}‘ where id=‘{$id}‘";

$r = $db->query($sql);
echo $sql;
if($r)
{
    header("location:chaxun.php");
}
else
{
    echo "失败";
}

(2)删除处理页面代码

<?php

$aa = $_GET["ass"];

$db = new MySQLi("localhost","root","212333","HouseDB");

$sql = "delete from house where id=‘{$aa}‘ ";

$r = $db->query($sql);

if($r)
{
    header("location:chaxun.php");
}
else
{
    echo "失败";
}

4.条件查询页面

<!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>
<form action="sousuo.php" method="post">
<div>区&nbsp;&nbsp;域:<input type="checkbox" onclick="checkall(this)" />全选</div>
<div>
    <input type="checkbox" name="a[]" value="坂井" class="qx1" />坂井
    <input type="checkbox" name="a[]" value="三义庙" class="qx1"/>三义庙
    <input type="checkbox" name="a[]" value="上上城" class="qx1" />上上城
    <input type="checkbox" name="a[]" value="天安门东" class="qx1" />天安门东
    <input type="checkbox" name="a[]" value="中关村" class="qx1" />中关村
</div>
<br />

<div>租赁类型:<input type="checkbox" onclick="checkall2(this)" />全选</div>
<div>
    <input type="checkbox" name="b[]" class="qx2"/>床位
    <input type="checkbox" name="b[]" class="qx2"/>合租
    <input type="checkbox" name="b[]" class="qx2"/>整租
</div>
<br />

<div>房屋类型:<input type="checkbox" name="qx" onclick="checkall3(this)" />全选</div>
<div>
    <input type="checkbox" name="c[]" class="qx3" />1室1厅
    <input type="checkbox" name="c[]" class="qx3" />2室1厅
    <input type="checkbox" name="c[]" class="qx3" />3室2厅
    <input type="checkbox" name="c[]" class="qx3" />4室2厅
    <input type="checkbox" name="c[]" class="qx3" />平房
    <input type="checkbox" name="c[]" class="qx3" />筒子楼
</div>
<br />
<div>关键字:<input type="text" name="gjz" /> </div>
<br />
<div><input type="submit" value="搜索" /></div>
</form>
<br />

<br />
<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["a"]) && count($_POST["a"])>0)
{
    $a = $_POST["a"];
    $b = implode("‘,‘",$a);
    $tj1 = " area in(‘{$b}‘) ";
}

if(!empty($_POST["b"]) && count($_POST["b"])>0)
{
    $b = $_POST["b"];
    $c = implode("‘,‘",$b);
    $tj2 = " area in(‘{$c}‘) ";
}

if(!empty($_POST["c"]) && count($_POST["c"])>0)
{
    $c = $_POST["c"];
    $d = implode("‘,‘",$c);
    $tj3 = " area in(‘{$d}‘) ";
}

if(!empty($_POST["gjz"]))
{
    $gjz = $_POST["gjz"];
    $tj4 = " keyword like ‘%{$gjz}%‘ ";
}

$db = new MySQLi("localhost","root","212333","HouseDB");

$sqls = "select * from house where {$tj1} and {$tj2} and {$tj3} and {$tj4}";

$results = $db->query($sqls);

$attr = $results->fetch_all();

foreach($attr as $j)
    {
        echo "<tr>
                <td>$j[1]</td>
                <td>$j[2]</td>
                <td>$j[3]</td>
                <td>$j[4]</td>
                <td>$j[5]</td>
                <td>$j[6]</td>
             </tr>";
    }

?>

</table>

</body>

<script type="text/javascript">

function checkall(a)
{
    var ck = document.getElementsByClassName("qx1");

    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");
        }
    }
}

function checkall2(a)
{
    var ck = document.getElementsByClassName("qx2");

    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");
        }
    }
}
function checkall3(a)
{
    var ck = document.getElementsByClassName("qx3");

    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>
</html>

时间: 2024-11-05 12:15:05

租房子查询的相关文章

租房子查询练习

<form action="chaxun.php" method="post"> <?php include "zu.class.php"; $db = new zu(); echo "区域: <input type='checkbox' id='quq' onclick='qy()' />全选 <br><br> "; $sql = "select distinc

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

练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php 1 <?php 2 class DBDA 3 { 4 public $fuwuqi="localhost"; //服务器地址 5 public $yonghuming="root";//用户名 6 public $mima="";//密码 7 8 public $dbconnect;

复选框式查询 例题租房子

<!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-

练习题投票和租房子

一:投票,连个页面都引用了DBDA封装类 <!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

增删改查租房子练习题

租房子练习题:重要颜色 1.模仿get传值到处理php页面:<a href='shanchu.php?c={$v[0]}' onclick=\"return confirm('确定删除吗?')\">删除</a> 2.删除页面显示确定删除提示框:<a href='shanchu.php?c={$v[0]}' onclick=\"return confirm('确定删除吗?')\">删除</a> 主页面: <body

php封装+租房子练习题

第一个页面DBDA.class.php <?php class DBDA { public $host = "localhost"; public $uid = "root"; public $pwd = "root"; public $dbname = "dbname"; public function Query($sql,$type=1)//两个参数,第二个参数代表默认值 { $db = new MySQLi($t

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

一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming="root";//用户名 public $mima="";//密码 public $dbconnect;//连接对象 //操作数据库的方法 //$sql代表需要执行的SQL语句 //$type代表SQL语句的类型,1代表查询,2代表增删

php之租房子练习

一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming="root";//用户名 public $mima="";//密码 public $dbconnect;//连接对象 //操作数据库的方法 //$sql代表需要执行的SQL语句 //$type代表SQL语句的类型,1代表查询,2代表增删

php租房子批量搜索例题

租房子例题是用来练习多条件查询以及批量选择的典型例题,题面是这样的: 首先要分别建立区域.租赁类型.房屋类型的复选界面,遍历出所有数据,这里用无边框表格创建: <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td>区域:<input type="checkbox" name="qx" onclic