Home  >  Article  >  Backend Development  >  PHP implements three-level cascading drop-down box, multi-select drop-down box, drop-down box plug-in, drop-down box code

PHP implements three-level cascading drop-down box, multi-select drop-down box, drop-down box plug-in, drop-down box code

WBOY
WBOYOriginal
2016-07-29 08:53:101132browse

This is the information I found on the Internet about implementing three-level cascading drop-down boxes in PHP. I would like to share it with you so that everyone can make progress together. The specific content is as follows

index.php:





 XMLHttpRequest对象的status属性值为200 , html文件在本地运行,则xmlHttp.status的返回值为0,故应该加上xmlHttp.status==0
 if(xmlHttp.status==200 || xmlHttp.status==0)     //调用文档对象模型DOM的getElementById()方法查找html文件中的标签txtHint ,
     //innerHTML为IE浏览器中的属性,可以用来更改标签间文本的内容 ,
     //xmlHttp.responseText , 通过XMLHttpRequest的responseText属性来获取数据 responseText,结果为字符串;responseXML,结果为XML形式
//     document.getElementByIdx_x_xx_x_xx("txtHint").innerHTML=xmlHttp.responseText
     BuildSel(xmlHttp.responseText,document.getElementsByTagName_r("*").sel2)
     showMenu2(document.getElementsByTagName_r("*").sel2.value); }
}
//函数stateChanged() - 响应HTTP请求状态变化
function stateChanged2() //判断XMLHttpRequest对象的readyState属性值是否为4,如果为4表示异步调用完成(注意:异步调用完成 不代表 异步调用成功)
if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") //如果异步调用成功 --> XMLHttpRequest对象的status属性值为200 , html文件在本地运行,则xmlHttp.status的返回值为0,故应该加上xmlHttp.status==0
 if(xmlHttp2.status==200 || xmlHttp2.status==0)     //调用文档对象模型DOM的getElementById()方法查找html文件中的标签txtHint ,
     //innerHTML为IE浏览器中的属性,可以用来更改标签间文本的内容 ,
     //xmlHttp.responseText , 通过XMLHttpRequest的responseText属性来获取数据 responseText,结果为字符串;responseXML,结果为XML形式
//     document.getElementByIdx_x_xx_x_xx("txtHint").innerHTML=xmlHttp.responseText
     BuildSel(xmlHttp2.responseText,document.getElementsByTagName_r("*").sel3) }
}
//函数GetXmlHttpObject() - 创建XMLHttpRequest对象,即创建一个异步调用对象
function GetXmlHttpObject() var xmlHttp=null;
try // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest(); catch (e) //Internet Explorer
 try  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); catch (e)  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
return xmlHttp; -->

get2.php

<?php header('Content-Type:text/html;charset=GB2312'); $conn = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
mysql_select_db('fitment', $conn) or die ('Can\'t use database : ' . mysql_error());
mysql_query("set names 'gb2312'");
//如果传递过来q
if($_GET["q"]){
$strs = "SELECT * FROM fitment_sort WHERE supid=' ".$_GET["q"]."' ";
//echo $str;
$results = mysql_query($strs) or die("Invalid query: " . mysql_error());
if($results)   while ($arrs = mysql_fetch_array($results)){
    $strings .= $arrs["id"]."|".$arrs["name"].",";   }
  echo substr($strings,0,strlen($strings)-1); }
//如果传递过来q2
if($_GET["q2"]){
$str = "SELECT * FROM fitment_sort WHERE supid= '".$_GET["q2"]."'";
//echo $str;
$result = mysql_query($str) or die("Invalid query: " . mysql_error());
if($result)   while ($arr = mysql_fetch_array($result)){
    $string .= $arr["id"]."|".$arr["name"].",";   }   echo substr($string,0,strlen($string)-1); }
mysql_close($conn);
?>

The above is the relevant code for implementing three-level cascading drop-down boxes in PHP. I hope it will be helpful for everyone to learn PHP programming.

The above introduces the implementation of three-level cascading drop-down boxes in PHP, including the contents of PHP and drop-down boxes. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn