一、题目要求

二、题目做法

1.建立数据库

2.封装类文件

  1. <?php
  2. class DBDA
  3. {
  4. public $fuwuqi="localhost"; //服务器地址
  5. public $yonghuming="root";//用户名
  6. public $mima="";//密码
  7. public $dbconnect;//连接对象
  8. //操作数据库的方法
  9.  
  10. //$sql代表需要执行的SQL语句
  11. //$type代表SQL语句的类型,1代表查询,2代表增删改
  12. //$shujukuming代表数据库的名称
  13. //如果是查询,返回二维数组
  14. //如果是增删改,返回true或false
  15.  
  16. function Query($sql,$type=1,$shujukuming="house")
  17. {
  18. //造连接对象
  19. $this->dbconnect = new MySQLi($this->fuwuqi,$this->yonghuming,$this->mima,$shujukuming);
  20.  
  21. //判断是否出错
  22. if(!mysqli_connect_error())
  23. {
  24. //如果连接成功,执行SQL语句
  25. $result = $this->dbconnect->query($sql);
  26.  
  27. //根据语句类型判断
  28. if($type==1)
  29. {
  30. //如果是查询语句,返回二维数组
  31. return $result->fetch_all();
  32. }
  33. else
  34. {
  35. //如果是其他语句,返回true或false
  36. return $result;
  37. }
  38.  
  39. }
  40. else
  41. {
  42. return"连接失败";
  43. }
  44. }
  45. }
  46. ?>

3.租房子首页

  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. <body>
  8.  
  9. <table width="1000px" cellpadding="1" border="1" ellspacing="1">
  10. <tr>
  11.  
  12. <td>关键字</td>
  13. <td>区域</td>
  14. <td>使用面积</td>
  15. <td>租金</td>
  16. <td>租贷类型</td>
  17. <td>房屋类型</td>
  18. <td></td>
  19. <td></td>
  20. </tr>
  1. <?php
  2.  
  3. include("DBDA.class.php");
  4.  
  5. $dx=new DBDA();
  6.  
  7. $sql="select * from house";
  8. $r = $dx->Query($sql,1);
  9. //$attr=$result->fetch_all();
  10.  
  11. foreach($r as $v)
  12. {
  13. echo
  14. "<tr>
  15.  
  16. <td>{$v[1]}</td>
  17. <td>{$v[2]}</td>
  18. <td>{$v[3]}</td>
  19. <td>{$v[4]}</td>
  20. <td>{$v[5]}</td>
  21. <td>{$v[6]}</td>
  22. <td><a href='bianji.php?id={$v[0]}'>编辑</a></td>
  23. <td><a href='shanchuchuli.php?id={$v[0]}' onclick=\"return confirm('确定删除吗')\">删除</a></td>
  24. </tr>";
  25. }
  26.  
  27. ?>
  1. </table>
  2. <br />
  3. <br />
  4. <a href="tianjiashuju.php"><input type="button" value="添加数据"/></a>
  5. <a href="duotiaojianchaxun.php"><input type="button" value="搜索查询" /></a>
  6. </title>
  7. </body>
  8. </html>

(4)删除数据处理页面

  1. <?php
  2. $id = $_GET["id"];
  3. var_dump($newsid);
  4.  
  5. include("DBDA.class.php");
  6.  
  7. $dx=new DBDA();
  8.  
  9. $sql = "delete from House where id='{$id}'";
  10. $r = $dx->Query($sql,2);
  11. if($r)
  12. {
  13. header("location:liebiaoyemian.php");
  14. }
  15. else
  16. {
  17. echo "删除失败!";
  18. }

5.编辑页面

  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. <body>
  8. <!--newsid--><center>
  9. <h1>修改房屋数据</h1>
  1. <?php
  2.  
  3. $id = $_GET["id"];
  4.  
  5. include("DBDA.class.php");
  6.  
  7. $dx=new DBDA();
  8.  
  9. //echo "id";
  10. //var_dump($id);
  11.  
  12. $sql="select * from house where id='{$id}'";
  13. $r=$dx->Query($sql);
  14.  
  15. ?>
  1. <form action="bianjichuli.php" method="post">
  2.  
  3. <input type="hidden" name="id" value="<?php echo $r[0][0];?>"/><!--id传过的ID-->
  4.  
  5. <div>关键字:<input type="text" name="KeyWord" value="<?php echo $r[0][1];?>"/></div>
  6. <div>区域:<input type="text" name="Area" value="<?php echo $r[0][2];?>"/></div>
  7. <div>使用面积:<input type="text" name="SquareMeter" value="<?php echo $r[0][3];?>"/></div>
  8. <div>租金:<input type="text" name="Rent" value="<?php echo $r[0][4];?>"/></div>
  9. <div>租贷类型:<input type="text" name="RentType" value="<?php echo $r[0][5];?>"/></div>
  10. <div>房屋类型:<input type="text" name="HouseType" value="<?php echo $r[0][6];?>"/></div>
  11.  
  12. <div><input type="submit" value="更新"/></div>
  13.  
  14. </form>
  15. <!--<a href="chakan.php"><input type="button" value="查看"></a>-->
  16. </center>
  17. </body>
  18. </html>

6.编辑处理页面

  1. <?php
  2.  
  3. //使用加载类
  4.  
  5. include("DBDA.class.php");
  6. $db = new DBDA();
  7. $id=$_POST["id"];//传ID
  8. $KeyWord = $_POST["KeyWord"];
  9. $Area = $_POST["Area"];
  10. $SquareMeter = $_POST["SquareMeter"];
  11. $Rent = $_POST["Rent"];
  12. $RentType = $_POST["RentType"];
  13. $HouseType = $_POST["HouseType"];
  14. $sql="update house set KeyWord='{$KeyWord}',Area='{$Area}',SquareMeter='{$SquareMeter}',Rent='{$Rent}',RentType='{$RentType}',HouseType='{$HouseType}' where id='{$id}'";// where id='{$id}
  15.  
  16. //echo $sql;
  17.  
  18. $attr = $db->Query($sql,2);
  19. //var_dump($attr);
  20. if($attr)
  21. {
  22. header("location:liebiaoyemian.php");
  23. }
  24. else
  25. {
  26. echo "修改失败";
  27. }

7.添加数据页面

  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.  
  7. </head>
  8. <style>
  9. .kong
  10. {
  11. margin:10px 0px 10px 0px;
  12. vertical-align:
  13. }
  14. </style>
  15. <body>
  16. <form action="tianjiachili.php" method="post">
  17.  
  18. <h3>添加房屋信息页面</h3>
  19.  
  20. <div class="kong">
  21. 关键字:
  22. <input type="text" name="KeyWord"/>
  23. </div>
  24. <div class="kong">
  25. 区域:
  26. <input type="text" name="Area"/>
  27. </div>
  28. <div class="kong">
  29. 使用面积:
  30. <input type="text" name="SquareMeter"/>
  31. </div>
  32. <div class="kong">
  33. 租金:
  34. <input type="text" name="Rent">
  35. </div>
  36. <div class="kong">
  37. 租赁类型:
  38. <input type="text" name="RentType"/>
  39. </div>
  40. <div class="kong">
  41. 房屋类型
  42. <input type="text" name="HouseType"/>
  43. </div>
  44. <div>
  45. <input type="submit" value="确定"/><!--插入信息-->
  46. <a href="liebiaoyemian.php"><input type="button" value="返回主页" /></a>
  47. </div>
  48. </form>
  49.  
  50. </body>
  51. </html>

8.添加数据处理页面

  1. <?php
  2. //$id = $_POST["id"];
  3. $KeyWord = $_POST["KeyWord"];
  4. $Area = $_POST["Area"];
  5. $SquareMeter = $_POST["SquareMeter"];
  6. $Rent = $_POST["Rent"];
  7. $RentType = $_POST["RentType"];
  8. $HouseType = $_POST["HouseType"];
  9.  
  10. //造连接对象
  11. include("DBDA.class.php");
  12. $db=new DBDA();
  13.  
  14. //写sql语句
  15. $sql="insert into house values('','{$KeyWord}','{$Area}','{$SquareMeter}','{$Rent}','{$RentType}','{$HouseType}')";
  16. //执行语句
  17. $r=$db->Query($sql,2);//($sql,2) 2代表增删改 错在了2上
  18.  
  19. if($r)
  20. {
  21. header("location:liebiaoyemian.php");
  22. }
  23. else{
  24. echo "执行失败!";
  25. }
  26. ?>

9.搜索页面(多条件查询)

  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.  
  10. <body>
  11. <form action="duotiaojianchaxun.php" method="post">
  12. <div>区域:<input type="checkbox" onclick="CheckAll(this,'qy')" />全选</div>
  13. <div>
  1. <?php
  2. include("DBDA.class.php");
  3. $db = new DBDA();
  4.  
  5. $sqlqy = "select distinct Area from house";
  6. $attrqy = $db->Query($sqlqy);
  7. //var_dump($attrqy);
  8.  
  9. foreach($attrqy as $v)
  10. {
  11. echo "<input class='qy' type='checkbox' value='{$v[0]}' name='qy[]'/>{$v[0]} ";
  12. }
  13. ?>
  1. </div><br />
  2.  
  3. <div>租赁类型:<input type="checkbox" onclick="CheckAll(this,'zl')" />全选</div>
  4. <div>
  1. <?php
  2.  
  3. $sqlzl = "select distinct RentType from House";
  4. $attrzl = $db->Query($sqlzl);
  5.  
  6. foreach($attrzl as $v)
  7. {
  8. echo "<input class='zl' type='checkbox' value='{$v[0]}' name='zl[]'/>{$v[0]} ";
  9. }
  10. ?>
  1. </div><br />
  2.  
  3. <div>房屋类型:<input type="checkbox" onclick="CheckAll(this,'fw')" />全选</div>
  4. <div>
  1. <?php
  2.  
  3. $sqlfw = "select distinct HouseType from House";
  4. $attrfw = $db->Query($sqlfw);
  5. //var_dump($attrqy);
  6.  
  7. foreach($attrfw as $v)
  8. {
  9. echo "<input class='fw' type='checkbox' value='{$v[0]}' name='fw[]'/>{$v[0]} ";
  10. }
  11. ?>
  1. </div><br />
  2.  
  3. <div>关键字:<input type="text" name="keyword" id="key" />
  4. </form>
  5. <br />
  6. <input type="submit" value="搜索" />
  7.  
  8. <br />
  9. <br />
  10. <br />
  11.  
  12. <table cellpadding="1" cellspacing="1" border="1" width="100%">
  13. <tr>
  14. <td>关键字</td>
  15. <td>区域</td>
  16. <td>面积</td>
  17. <td>租金</td>
  18. <td>租赁类型</td>
  19. <td>房屋类型</td>
  20. </tr>
  1. <?php
  2.  
  3. $tj = "";
  4. $tj1 = "1=1";
  5. $tj2 = "1=1";
  6. $tj3 = "1=1";
  7. $tj4 = "1=1";
  8.  
  9. if(!empty($_POST["qy"]))
  10. {
  11. $attr = $_POST["qy"];
  12. $str = implode("','",$attr);
  13. $tj1 = " Area in ('{$str}')";
  14. }
  15.  
  16. if(!empty($_POST["zl"]))
  17. {
  18. $attr = $_POST["zl"];
  19. $str = implode("','",$attr);
  20. $tj2 = " RentType in ('{$str}')";
  21. }
  22.  
  23. if(!empty($_POST["fw"]))
  24. {
  25. $attr = $_POST["fw"];
  26. $str = implode("','",$attr);
  27. $tj3 = " HouseType in ('{$str}')";
  28. }
  29.  
  30. if(!empty($_POST["keyword"]))
  31. {
  32. $attr = $_POST["keyword"];
  33. $tj3 = " keyword like '%{$attr}%'";
  34. }
  35.  
  36. $tj = " Where {$tj1} and {$tj2} and {$tj3} and {$tj4}";//Where 前加空格
  37.  
  38. $sql = "select * from House".$tj;
  39. $attrall = $db->Query($sql);
  40. //var_dump($attrall);
  41.  
  42. foreach($attrall as $v)
  43. {
  44. echo "<tr>
  45. <td>{$v[1]}</td>
  46. <td>{$v[2]}</td>
  47. <td>{$v[3]}</td>
  48. <td>{$v[4]}</td>
  49. <td>{$v[5]}</td>
  50. <td>{$v[6]}</td>
  51. </tr>";
  52. }
  53.  
  54. ?>
  1. </table>
  2.  
  3. </body>
  4. <script type="text/javascript">
  5. function CheckAll(a,b)//this表示该
  6. {
  7. var qx = a.checked;
  8. var ck = document.getElementsByClassName(b);
  9. for(var i =0;i<ck.length;i++)
  10. {
  11. ck[i].checked = qx;
  12. }
  13. }
  14.  
  15. </script>
  16.  
  17. </html>
  18. </body>
  19. </html>

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封装+租房子练习题

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

  6. php练习 租房子

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

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

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

  8. PHP 练习3:租房子

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

  9. 2016/3/30 租房子 ①建立租房子的增、删、改php页面 ②多条件查询 ③全选时 各部分全选中 任意checkbox不选中 全选checkbox不选中

    字符串的另一种写法:<<<AAAA; 后两个AA回车要求顶格  不然报错 例子: <!DOCTYPE html> <html lang="en" ...

随机推荐

  1. react native中Unable to load script from assets 'index.android.bundle'解决方案

    刚刚朋友问我,说是创建好一个项目,运行后报错:Unable to load script from assets 'index.android.bundle',以前好好的没出现这种现象,于是我找到一个 ...

  2. Git删除文件

    Git基础 Git有三大区(工作区.暂存区.版本库),文件有三个状态(untracked.unstaged.uncommited). (1)打开项目文件夹,除了隐藏的.git文件夹,其他项目文件位于的 ...

  3. VMware部署ubuntu后开机提示piix4_smbus: Host SMBus controller not enabled!

    在虚拟机部署ubuntu10.04-server,每次启动完成之后,出现“piix4_smbus0000:00:07.3: Host SMBus controller not enabled!”提示信 ...

  4. 使用 HPC Pack 为 Azure 中的 Windows HPC 工作负荷创建和管理群集的选项

    利用 Microsoft HPC Pack 和 Azure 的计算与基础结构服务,创建和管理基于云的高性能计算 (HPC) 群集. HPC Pack 是在 Azure 和 Windows Server ...

  5. python基础知识回顾之元组

    元组与列表的方法基本一样,只不过创建元组是用小括号()把元素括起来,两者的区别在于,元组的元素不可被修改. 元组被称为只读列表,即数据可以被查询,但不能被修改,列表的切片操作适用于元组. 元组写在小括 ...

  6. 转:.NET 面试题汇总(二)

    目录 本次给大家介绍的是我收集以及自己个人保存一些.NET面试题第二篇 简介 1.接口 2.您在什么情况下会用到虚方法或抽象类,接口? 3.重载(Overload )和覆写(Override)的区别 ...

  7. UNIX高级环境编程(11)进程控制(Process Control)- 进程快照,用户标识符,进程调度

    1 进程快照(Process Accounting) 当一个进程终止时,内核会为该进程保存一些数据,包括命令的小部分二进制数据.CPU time.启动时间.用户Id和组Id.这样的过程称为proces ...

  8. [Python_4] Python 面向对象(OOP)

    0. 说明 Python 面向对象(OOP) 笔记.迭代磁盘文件.析构函数.内置方法.多重继承.异常处理 参考 Python面向对象 1. 面向对象 # -*-coding:utf-8-*- &quo ...

  9. Hadoop YARN简介

    背景 本文整理一些Hadoop YARN的相关内容. 简介 YARN(Yet Another Resource Negotiator)是Hadoop通用资源管理平台,为各类计算框架(离线MR.在线St ...

  10. 记录一次elasticsearch-php工作过程

    初始化 $hosts = array('192.168.30.41'); $this->client = \Elasticsearch\ClientBuilder::create()->s ...