威尼斯登录首页您看经过list.php来进展数据库查询
分类:威尼斯登录首页

上面包车型大巴多少个公文copy到同贰个文本下,通过web路线访谈index.html看看吧,这么些是通过iframe来得以达成的连动更新,list.php近期的剧情比较轻便,你看经过list.php来张开数据库查询,然后展现出查询的结果列表。index.htmlbodyform name="myfrm"select name="mlist" onchange="changes(State of Qatar;"option value="0"请采纳.../optionoption value="新加坡"法国首都/optionoption value="南平"松原/option/selectnbsp;select name="slist"/selectiframe src="list.php?city=" /iframescript language="javascript"function changes(卡塔尔(قطر‎{ frame.location.href = "list.php?city=" document.myfrm.mlist.value;}/script/form/bodylist.php?php $data = array("新加坡"=array("小强","旺财","小强他爹"卡塔尔(قطر‎, "盘锦"=array("小温","小宋","他们外甥"),State of Qatar; $city = $_GET["city"]; $result = $data[$city]; $str = "script language="javascript"list = parent.document.myfrm.slist;list.length = 0;"; if($result==null) $str .= "tmp = new Option("......", "");list.options[0] = tmp;"; else foreach($result as $i = $value) $str .= "tmp = new Option("{$value}", "{$value}");list.options[$i] = tmp;"; $str .= "/script"; echo $str;?

很简短的   

  1.先把  <script language="JavaScript" src="../include/js/regions.js"></script>
加到 header.html 页
  2.把 regionss() 函数 加到 /include/tag.php 里
  3.在你网址的根目录创设个  regions.php 文件
  4.在你的沙盘模拟经营的适当之处投入   {$regionss(中国卡塔尔(قطر‎}   就能够  

专一:  表单的名字可依据你的供给可以谐和修正...

测验页代码:
<html>
<head>
<meta http-equiv="Content-Type" c />
<title>php+ajax动态变化下拉菜单</title>
<script language="JavaScript" src="../include/js/regions.js"></script>
</head>
<body>
<form name="form1" method="post" action="">
<tr><td>{$regionss(中国卡塔尔}</td></tr>
</form>
</body>
</html>

regionss 函数代码:
//省市地3级联合浮动下拉菜单函数 regionss 省.市.地  
function regionss($country="中国"State of Qatar
{      
        global $db; $i = 1;
        $text="<select id="select1" name="select1" onchange="startRequest()" style="width:90px;"><option value="">省/市/自治区</option>n";
      
        $result = $db->query("SELECT province FROM ".TABLE_PROVINCE." WHERE country='$country' ORDER BY provinceid");
        while($r = $db->fetch_array($result))
         {
  $text .= "<option value=".$r['province'].">".$r['province']."</option> ";
  $i++;
         }
        $text.="</select>";
        $text.=" <select id="select2" name="select2" onchange="startRequesta()" style="width:90px;"><option value="">市/县/区</option></select>n";
        $text.="<select id="select3" name="select3" style="width:90px;"><option value="">县级市/县</option></select>n";   
        return $text;
                        
}

regions.js 的代码:

//var ab = new Array();
var xmlHttp;
var xmlHttpa;
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }  
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
function createXMLHttpRequesta() {
    if (window.ActiveXObject) {
        xmlHttpa = new ActiveXObject("Microsoft.XMLHTTP");
    }  
    else if (window.XMLHttpRequest) {
        xmlHttpa = new XMLHttpRequest();
    }
}  
   
function startRequest() {
    createXMLHttpRequest();
    createXMLHttpRequesta();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttpa.onreadystatechange = handleStateChangearea;
    document.getElementById('select2').options.length = 0;
    document.getElementById('select3').options.length = 0;
    var url = document.form1.select1.value;
    var qurl = "/regions.php?province="+url+"&time="+new Date().getTime();
    xmlHttp.open("GET", qurl, true);
    xmlHttp.send(null);
    //setTimeout("startRequest()",2000);
}
     
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
         var obj = document.getElementById('select2'卡塔尔(قطر‎; //将服务器重回的字符串写到页面中ID为select2的区域   
            obja = document.getElementById('select3'卡塔尔; //将服务器重临的字符串写到页面中ID为select3的区域   
            eval(xmlHttp.responseText);   
        
        }
    }
}
function handleStateChangearea() {         
            eval(xmlHttpa.responseText);         
}
//var ab = new Array();

function startRequesta() {
    createXMLHttpRequesta();
    xmlHttpa.onreadystatechange = handleStateChangea;
    document.getElementById('select3').options.length = 0;
    var url = document.form1.select2.value;
    var qurl = "/regions.php?city="+url+"&time="+new Date().getTime();
    xmlHttpa.open("GET", qurl, true);
    xmlHttpa.send(null);
    //setTimeout("startRequest()",2000);
}

function handleStateChangea() {
    if(xmlHttpa.readyState == 4) {
        if(xmlHttpa.status == 200) {
         var obja = document.getElementById('select3');
            eval(xmlHttpa.responseText);  
        //将服务器重临的字符串写到页面中ID为select3的区域
            
        }
    }
}

数据岛 regions.php 页面代码

<?php
require "common.php";
$city = $city ? $city : "";
$area = $area ? $area : "";
if($province && $city==''){
  global $db; $i = 1;
  
  $result = $db->query("SELECT DISTINCT city FROM ".TABLE_CITY." WHERE province='$province' ORDER BY cityid");
  while($r = $db->fetch_array($result))
    {
       $r[city]=iconv('gb2312','UTF-8',$r[city]);
echo "obj.options[obj.options.length] = new Option('".$r[city]."','".$r[city]."');n";
$i++;
    }
  $resultarea = $db->query("SELECT DISTINCT city FROM ".TABLE_CITY." WHERE province='$province' ORDER BY cityid");
  $r = $db->fetch_array($resultarea);
  $city = $r[city];
  $resulta = $db->query("SELECT DISTINCT area FROM ".TABLE_CITY." WHERE city='$city' ORDER BY cityid");
   while($ra = $db->fetch_array($resulta))
    {
       $ra[area]=iconv('gb2312','UTF-8',$ra[area]);
echo "obja.options[obja.options.length] = new Option('".$ra[area]."','".$ra[area]."');n";
$i++;
    }

}
if($city && $province==''){
   global $db; $i = 1;
  
   $result = $db->query("SELECT DISTINCT area FROM ".TABLE_CITY." WHERE city='$city' ORDER BY cityid");
   while($r = $db->fetch_array($result))
    {
       $r[area]=iconv('gb2312','UTF-8',$r[area]);
echo "obja.options[obja.options.length] = new Option('".$r[area]."','".$r[area]."');n";
$i++;
    }
}
?>

地点新闻数据库:

     选拔的是phpcms3.0里自带的数据库,笔者从不开展别的改造

本程序能够在phpcms3.0里直接使用,若在另各州方接收请自身修改

本文由威尼斯在线注册平台发布于威尼斯登录首页,转载请注明出处:威尼斯登录首页您看经过list.php来进展数据库查询

上一篇:系统中持有非亲非故的模块都或许通过出错.,种类中有着无关的模块都可能通过出错. 下一篇:1个集体艺术,PHP怎么贯彻目的实例化单例
猜你喜欢
热门排行
精彩图文