rentAction.class.php:
<?php
class rentAction extends Action{
public $tb_company;
public $tb_buildingpro;
public $tb_building;
public $tb_house;
public $tb_rent_person;
public $tb_rent_info; public function __construct(){
parent::__construct();
$this->tb_company=M('company');
$this->tb_buildingpro=M('buildingpro');
$this->tb_building=M('building');
$this->tb_house=M('house');
//$this->tb_house=M('rent_person');
//$this->tb_house=M('rent_info');
}
public function houserent(){
$companys=$this->tb_company->where("pid=1")->select();
$this->assign('data',$companys);
$this->display();
}
public function company(){ //公司联动楼盘
//var_dump($_POST['data']);
//echo $_POST['data'];
$company_id=$_POST['data'];  //接收模板文件jquery $(load)传来参数。data
$where['company_id']=$company_id;
$query=$this->tb_buildingpro->where($where)->select(); //在楼盘表buildingpro里找出字段company_id;=$company_id;
//var_dump($query[0][id]);
if($query){  //判断如果有数据就显示“请选择楼盘名称”  如果无数据就显示“无楼盘”
$temp="<option selected='selected'>--请选择楼盘名称--</option>";

}else{
$temp="<option selected='selected'>无楼盘</option>";
}

//循环数组
foreach ($query as $key=>$value)
{
$temp.="<option value=".$query[$key]['id'].">".$query[$key]['name']."</option>";

}
//var_dump($query);
//echo $m->getLastSql();
echo $temp;
}

public function buildingpro(){ //楼盘联动楼栋
//var_dump($_POST['data']);
//echo $_POST['data'];
$buildingpro_id=$_POST['data'];  //接收模板文件jquery $(load)传来参数。data
$where['buildingpro_id']=$buildingpro_id;
$query=$this->tb_building->where($where)->select();   //在楼栋表building里找出字段buildingpro_id=$buildingpro_id
//var_dump($query[0][id]);
if($query){  //判断如果有数据就显示“请选择楼名称”   如果无数据就显示“无楼栋”
$temp="<option selected='selected'>--请选择楼名称--</option>";

}else{
$temp="<option selected='selected'>无楼栋</option>";

}
//循环数组
foreach ($query as $key=>$value)
{

$temp.="<option value=".$query[$key]['building']['buildingpro_id'].">".$query[$key]['building_name']."</option>";
}
//var_dump($query);
//echo $m->getLastSql();

echo $temp;

}

public function  building(){ //楼栋联动房间
//var_dump($_POST['data']);
//echo $_POST['data'];
$data=$_POST['data'];  //接收模板文件jquery $(load)传来参数。data
//$where['building']=$building;
$query=$this->tb_house->where($data)->select();   //在房间表house里找出字段building=$building
//echo var_dump($query[0][id]);
if($query){  //判断如果有数据就显示“请选择房间号” 如果无数据就显示“无房间”
$temp="<option selected='selected'>--请选择房间号--</option>";
}else{
$temp="<option selected='selected'>无房间</option>";
}
//循环数组
foreach ($query as $key=>$value)
{
$temp.="<option value=".$query[$key]['id'].">".$query[$key]['room']."</option>";
}
//var_dump($query);
//echo $m->getLastSql();
echo $temp;
}
}
?>
控制器rentActiont对应的视图中的rent文件夹中的houserent.html文件:
<!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" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<title>无标题文档</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.STYLE1 {font-size: 12px}
.STYLE3 {font-size: 12px; font-weight: bold; }
.STYLE4 {
color: #03515d;
font-size: 12px;
}
.STYLE5 {
font-size: 16px;
font-family: "黑体";
}
.STYLE6 {font-size: 14px}
-->
</style>
<script type="text/javascript">
    function showsubmenu(sid) {
        whichEl = eval("submenu" + sid);
        imgmenu = eval("imgmenu" + sid);
        if (whichEl.style.display == "none") {
            eval("submenu" + sid + ".style.display=\"\";");
            imgmenu.background = "images/main_47.gif";
        }
        else {
            eval("submenu" + sid + ".style.display=\"none\";");
            imgmenu.background = "images/main_48.gif";
        }
    }
</script>
<!--主要修改下面的这一段程序-->
<script type="text/javascript">
    $(document).ready(function(){
        //公司联动楼盘
        $("#company").change(function(){
            var val=$(this).val();
            //alert(val);
            $("#buildingpro").load("__URL__/company",{data:val});
        });
        //楼盘联动楼栋 
        $("#buildingpro").change(function(){
            var val=$(this).val();
            //alert(val);
            $("#building").load("__URL__/buildingpro",{data:val});
        });
            //楼栋 联动房间 
        $("#building").change(function(){
            var val=$(this).val();
            alert(val);
            $("#house").load("__URL__/building",{data:val});
        });
    });
</script></head><body>  <tr>
    <td height="30" background="__PUBLIC__/images/tab_05.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12" height="30"><img src="__PUBLIC__/images/tab_03.gif" width="12" height="30" /></td>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="46%" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="5%"><div align="center"><img src="__PUBLIC__/images/tb.gif" width="16" height="16" /></div></td>
                <td width="95%" class="STYLE1"><span class="STYLE3">当前位置</span>:[房屋租赁管理]-房屋租赁]</td>
              </tr>
            </table></td>
            <td width="54%"><table border="0" align="right" cellpadding="0" cellspacing="0">
              <tr>
                <td width="80"><table width="90%" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td class="STYLE1"><div align="center">&nbsp;</div></td>
                    <td class="STYLE1"><div align="center">&nbsp;</div></td>
                  </tr>
                </table>
                </td>
                <td width="100">&nbsp;
                
                </td>
              </tr>
            </table></td>
          </tr>
        </table></td>
        <td width="16"><img src="__PUBLIC__/images/tab_07.gif" width="16" height="30" /></td>
      </tr>
    </table></td>
  </tr>
  
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="8" background="__PUBLIC__/images/tab_12.gif">&nbsp;</td>
        <td>
          <table runat="server" width="100%">
  
        <tr>
          <td height="100%">
            <div style=" border:2px solid #C4D9F7;">
               <table runat="server" width="100%" style="height:373px">
                 <tr>
    <td valign="top">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>
        <form action="{:U('rent/houserent')}" method="post" onsubmit="return check_form_content();" enctype="multipart/form-data">
        <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6" onmouseover="changeto()"  onmouseout="changeback()">
         <tr>  
            <td height="30" colspan="6" bgcolor="#FFFFFF" class="STYLE3 STYLE5 STYLE6">房源信息</td>
          </tr>
          
  <tr>
         
            <td width="9%" height="25" bgcolor="#FFFFFF"><div align="right"><span class="STYLE1"><b>公司名称:</b></span></div></td>

<td  bgcolor="#FFFFFF"  width="25%" height="25">
  <div align="left"><span class="STYLE1">
  <!--主要修改下面的这一段程序-->
    <select name="company" class="input_style1"  id="company" >
        <option  selected="selected">--请选择公司--</option>
      <volist name="data" id="val">
        <option value="{$val.id}">{$val.name}</option>
        </volist>
      </select>
    &nbsp;<font color="#ff0000">*</font> </span> </div></td>

<td width="8%" height="25" bgcolor="#FFFFFF"><div align="right"><span class="STYLE1"><b>楼盘项目:</b></span></div></td>

<td  bgcolor="#FFFFFF" width="25%" height="25">
             <div align="left"><span class="STYLE1">
             <select name="buildingpro"  class="input_style1" id="buildingpro">
             </select>
             &nbsp;<font color="#ff0000">*</font> </span></div> </td>

            <td width="8%" height="25" bgcolor="#FFFFFF"><div align="right"><span class="STYLE1"><b>楼号:</b></span></div></td>

<td  bgcolor="#FFFFFF" width="25%" height="25">
             <div align="left">
             <span class="STYLE1">
             <select name="building" class="input_style1" id="building">
             </select>
             &nbsp;<font color="#ff0000">*</font>             </span>             </div>            </td>
          </tr>
</body>
</html>
实现多级联动的功能:请选择公司=》请选择楼盘名称=》请选择楼栋=》请选择房间号
选择公司通过公司的id联动楼盘的中的楼盘号id(company_id=公司id),然后通过楼盘号id联动楼栋的楼号building(buildingpro_id=楼盘id),然后再通过楼盘号和楼号来联动房间号(在房间表house中实现,我就在这一步没有实现)
本人已实现联动的功能,但是还是有两个问题没解决:
1、当重新选择公司的时候,后面的下拉框没有变化(我要的是都要一起变化)
2、当选择“房间号”的时候,我的程序里是通过楼号来查询来显示的房间号(这种做法的结果出现相同的房间号),正确的是通过房间表house中的builing(楼号)和builingpro_id(楼盘号)来查询其对应的房间号
本人新手,不怎么会,还请各位大神指教,急需这个具体的程序做个房地产的小功能,非常感谢各位哈。