希望这篇文章中给出的PHP二级联动菜单代码示例能够帮助大家提高实际编程能力,增加自己的知识库,巩固已掌握的知识。
对于初学者来说,PHP语言的掌握还是需要在具体实践中不断的去积累经验来增加我们对PHP的理解程度。下面就以一个范例为大家介绍PHP二级联动菜单的实现方法。#t#
PHP二级联动菜单代码示例:
- <scriptlanguage="JavaScript">
- varonecount;
- onecount=0;
- subcat=newArray();
- <?php
- mysql_connect("localhost","charles",
"charles"); - mysql_select_db("_crm");
- $sql="select*fromsite";
- $result=mysql_query($sql);
- $count=0;
- while($res=mysql_fetch_row($result)){
- ?>
- subcat[<?phpecho$count?>]=newArray
("<?phpecho$res[0]?>","<?phpecho
$res[2]?>","<?phpecho$res[1]?>"); - <?php
- $count++;
- }
- echo"onecount=$count;";
- ?>
- //联动函数
- functionchangelocation(locationid)
- {
- document.myform.ctype.length=0;
- varlocationidlocationid=locationid;
- vari;
- for(i=0;i<onecount;i++)
- {
- if(subcat[i][2]==locationid)
- {
- //varnewnewOption1=newOption(subcat[i]
[1],subcat[i][0]); - //document.all.ctype.add(newOption1);
- document.myform.ctype.options[document.
myform.ctype.length]=newOption(subcat
[i][1],subcat[i][0]); - }
- }
- }
- </script>
- <formmethod="post"name="myform"
action="ru_query.php"> - <selectname="type"onChange="changelocation(
document.myform.type.options[document.myfo
rm.type.selectedIndex].value)"size="1"> - <optionselectedvalue="">main</option>
- <?php
- $sql="select*fromentreprise";
- $result=mysql_query($sql);
- while($res=mysql_fetch_row($result)){
- ?>
- <optionvalue="<?phpecho$res[0];?>">
- <?phpecho$res[1];?></option>
- <?php}?>
- </select>
- <selectname="ctype">
- <optionselectedvalue="">sub</option>
- </select>
- <inputtype="submit"name="Submit"value="search">
- </form>
以上代码就是PHP二级联动菜单的具体实现方法。
转载请说明出处
知优网 » 代码示例展现PHP二级联动菜单的实现(php二级联动下拉列表)
知优网 » 代码示例展现PHP二级联动菜单的实现(php二级联动下拉列表)