21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
//根据id取得相关变量
/*$id=$_GET['id'];
$conn=mysql_connect("localhost","root","passport");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from table where id='$id'";
mysql_connect($sql,$conn);
while($row=mysql_fetch_row($result)){
$dprovince=$row['provincecode']; //山西省
$dcity=$row['citycode']; //大同市
$darea=$row['areacode'];
}*/
//娴嬭瘯鍙橀噺涓?缁勮褰曟樉绀?
//测试值
$dprovince="140000"; //山西省
$dcity='140200'; //大同市
$darea='140227'; //大同县
//if($id)
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function queryCity(citycode){
createXMLHttpRequest();
type="city";
var url="data.php?provincecode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}
function queryArea(citycode){
createXMLHttpRequest();
type="area";
var url="data.php?citycode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(type=="city"){
showcity();
}else if(type="area"){
showarea();
}
}
}
}
function showcity(){
document.getElementById("city").innerHTML=xmlHttp.responseText;
document.getElementById("area").innerHTML="";
}
function showarea(){
document.getElementById("area").innerHTML=xmlHttp.responseText;
}
</script>
</head>
<body>
<?PHP
$conn=mysql_connect("localhost","root","passport");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from province";
$result=mysql_query($sql);
echo "<from id='form1'>";
echo "<select id='province' onchange='queryCity(this.options[this.selectedIndex].value)'>";
//濡傛灉鎻愬彇鍑烘潵鐨勭渷鍊煎瓨鍦?
if($dprovince){
echo "<option value='-1' >璇烽?夋嫨鐪佷唤</option>";
}else{
echo "<option value='-1' selected>璇烽?夋嫨鐪佷唤</option>";
}
while($row=mysql_fetch_row($result)){
if($row[1]==$dprovince){
echo "<option value='$row[1]' selected>$row[2]</option>";
}else{
echo "<option value='$row[1]'>$row[2]</option>";
}
}
echo "</select>";
echo '</span>';
//鍩庡競浠g爜
echo "<span id='city'>";
echo "<select onchange='queryArea(this.options[this.selectedIndex].value)'>";
if($dprovince){
$sql="select * from city where provincecode=$dprovince";
$result=mysql_query($sql,$conn);
if($dcity){
echo "<option value='-1' >璇烽?夋嫨鍩庡競</option>";
}else{
echo "<option value='-1' selected>璇烽?夋嫨鍩庡競</option>";
}
while($row=mysql_fetch_row($result)){
if($row[1]==$dcity){
echo "<option value='$row[1]' selected>$row[2]</option>";
}else{
echo "<option value='$row[1]'>$row[2]</option>";
}
}
}
echo "</select>";
echo '</span>';
//鏄剧ず鍦板尯
echo "<span id='area'>";
if($dprovince && $dcity){
$sql="select * from area where citycode=$dcity";
$result=mysql_query($sql,$conn);
echo "<select>";
if($darea){
echo "<option value='-1' >璇烽?夋嫨鍘垮尯</option>";
}else{
echo "<option value='-1' selected>璇烽?夋嫨鍘垮尯</option>";
}
while($row=mysql_fetch_row($result)){
if($row[1]==$darea){
echo "<option value='$row[1]' selected>$row[2]</option>";
}else{
echo "<option value='$row[1]'>$row[2]</option>";
}
}
}
echo '</span>';
echo "</form>";
?>
</body>
</html>
<?php
if($_GET['act']=='insert')
{
echo "one-value:".$_POST['province']."<br>";
echo "two-value:".$_POST['city']."<br>";
echo "three-value".$_POST['area']."<br>";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function queryCity(citycode){
createXMLHttpRequest();
type="city";
var url="data.php?provincecode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}
function queryArea(citycode){
createXMLHttpRequest();
type="area";
var url="data.php?citycode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(type=="city"){
showcity();
}else if(type="area"){
showarea();
}
}
}
}
function showcity(){
var return_value=xmlHttp.responseText.split('|');
document.getElementById("city").length=0;
for(var i=0;i<return_value.length;i++)
{
new_option=return_value[i].split(',');
option_text=new_option[0];
option_value=new_option[1];
document.getElementById("city").options.add(new Option(option_value,option_text));
}
}
function showarea(){
document.getElementById("area").length=0;
var return_value=xmlHttp.responseText.split('|');
for(var i=0;i<return_value.length;i++)
{
new_option=return_value[i].split(',');
option_text=new_option[0];
option_value=new_option[1];
document.getElementById("area").options.add(new Option(option_value,option_text));
}
}
function get_value(action)
{
/*
获取到数据以后就用ajax去插入和更新。要不然表单提交以后就会刷新的了。
*/
var provinces=document.form1.province.value;
var citys=document.form1.city.value;
var areas=document.form1.area.value;
alert("进行的动作是:"+action);
alert("省ID:"+provinces);
alert("市ID:"+citys);
alert("区域ID:"+areas);
}
</script>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from province";
$result=mysql_query($sql);
?>
<form action="?act=insert" method="POST" name="form1" onsubmit="set_value();">
<select onchange='queryCity(this.options[this.selectedIndex].value)' id='province' name="province">
<?php
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
?>
</select>
<select id="city" onchange='queryArea(this.options[this.selectedIndex].value)' name="city"></select>
<select id="area" name="area"></select>
<input type="button" onclick="get_value('insert')" value="insert">
<input type="button" onclick="get_value('update')" value="update">
</form>
</body>
</html>
<?
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
if($provincecode!=""&&$provincecode!=650000&&$provincecode!=710000&&$provincecode!=810000&&$provincecode!=820000&&$provincecode!=110000&&$provincecode!=120000&&$provincecode!=310000&&$provincecode!=500000){
$sql="select * from city where provincecode=$provincecode";
$result=mysql_query($sql);
while($row=mysql_fetch_row($result)){
$str.=$row[1].",".$row[2]."|";
}
echo $str;
}
if($citycode!=""){
$sql="select * from area where citycode=$citycode";
$result=mysql_query($sql);
while($row=mysql_fetch_row($result)){
$str.=$row[1].",".$row[2]."|";
}
echo $str;
}
?>
<?php
if($_GET['act']=='insert')
{
echo "one-value:".$_POST['province_one']."<br>";
echo "two-value:".$_POST['province_two']."<br>";
echo "three-value".$_POST['province_three']."<br>";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function queryCity(citycode){
createXMLHttpRequest();
type="city";
var url="data.php?provincecode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}
function queryArea(citycode){
createXMLHttpRequest();
type="area";
var url="data.php?citycode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(type=="city"){
showcity();
}else if(type="area"){
showarea();
}
}
}
}
function showcity(){
document.getElementById("city").innerHTML=xmlHttp.responseText;
document.getElementById("area").innerHTML="";
}
function showarea(){
document.getElementById("area").innerHTML=xmlHttp.responseText;
}
</script>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from province";
$result=mysql_query($sql);
echo "<form name='form1' action='?act=insert' method='post'>\n";
echo "<select id='province' name='province_one' onchange='queryCity(this.options[this.selectedIndex].value)'>\n";
echo "<option value='-1' selected>请?择省份</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
echo "<span id='city'></span>\n";
echo "<span id='area'></span>\n";
echo "<input type='submit'>";
echo "</form>\n";
?>
</body>
</html>
<?
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
if($provincecode!=""&&$provincecode!=650000&&$provincecode!=710000&&$provincecode!=810000&&$provincecode!=820000&&$provincecode!=110000&&$provincecode!=120000&&$provincecode!=310000&&$provincecode!=500000){
$sql="select * from city where provincecode=$provincecode";
$result=mysql_query($sql);
echo "<select onchange='queryArea(this.options[this.selectedIndex].value)' name='province_two'>\n";
echo "<option value='-1' selected>ffsdfsf</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
}
if($citycode!=""){
$sql="select * from area where citycode=$citycode";
$result=mysql_query($sql);
echo "<select name='province_three'>\n";
echo "<option value='-1' selected>fsdfsfs</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
}
?>