<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post/149/</link>
<title><![CDATA[PHP+mysql实现全动态二级联动下拉列表]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[代码编程]]></category>
<pubDate>Wed, 18 Oct 2006 08:33:52 +0000</pubDate> 
<guid>http://www.dzhope.com/post/149/</guid> 
<description>
<![CDATA[ 
	二级联动下拉列表（select）,都是从数据库中取值，其中第二级为可多选列表（multiple）.若要实现二级也是下拉菜单，可以将multiple改了即可。<br/><br/>&lt;html&gt;<br/>&lt;head&gt;<br/>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot;&gt;<br/>&lt;title&gt;全动态二级联动下拉列表&lt;/title&gt;<br/>&lt;/head&gt;<br/>&lt;body&gt;<br/>&lt;?<br/>/***********************************************<br/>** 功 &nbsp;能：PHP+mysql实现二级级联下拉框 <br/>** 数据库：数据库名（db_city）、数据表（t_province、t_city）<br/>** 表t_province中字段：id（id编号）、provinceName（省份名）<br/>** 表t_city中的字段：id（id编号）、provinceId（省份ID）、cityName（城市名）<br/>***********************************************/<br/><br/>//****************** 连接选择数据库 ***************<br/>$link = mysql_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;123&quot;)<br/> &nbsp; &nbsp; &nbsp; &nbsp;or die(&quot;Could not connect : &quot; . mysql_error()); <br/>mysql_select_db(&quot;db_city&quot;) or die(&quot;Could not select database&quot;);<br/><br/>//******************提取省份信息******************<br/>$sqlSel = &quot;select * from t_province order by id &quot;;<br/>$result = mysql_query($sqlSel) or die(&quot;Query failed : &quot; . mysql_error()); <br/><br/>$forum_data = array();<br/>while( $row = mysql_fetch_array($result) )<br/>{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$forum_data[] = $row;<br/>}<br/>//print_r ($forum_data);<br/>mysql_free_result($result);<br/><br/>//**************获取城市信息************** &nbsp; &nbsp; &nbsp; &nbsp;<br/>$sqlSel2 = &quot;select * from t_city order by provinceId desc&quot;;<br/><br/>if( !($result2 = mysql_query($sqlSel2)) )<br/>{<br/> &nbsp; &nbsp; &nbsp; &nbsp;die(&#039;Could not query t_city list&#039;);<br/>}<br/><br/>$forum_data2 = array();<br/>while( $row2 = mysql_fetch_array($result2) )<br/>{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$forum_data2[] = $row2;<br/>}<br/><br/>mysql_free_result($result2);<br/>?&gt;<br/><br/>&lt;!--************ JavaScript处理province--onChange *************--&gt;<br/>&lt;script language = &quot;JavaScript&quot;&gt; <br/>var onecount2; <br/>subcat2 = new Array(); <br/>&lt;?php <br/>$num2 = count($forum_data2);<br/>?&gt;<br/>onecount2=&lt;?echo $num2;?&gt;;<br/>&lt;?<br/>for($j=0;$j&lt;$num2;$j++)<br/>{<br/>?&gt;<br/>subcat2[&lt;?echo $j;?&gt;] = new Array(&quot;&lt;?echo $forum_data2[$j][&#039;id&#039;];?&gt;&quot;,&quot;&lt;?echo $forum_data2[$j][&#039;provinceId&#039;];?&gt;&quot;,&quot;&lt;?echo $forum_data2[$j][&#039;cityName&#039;];?&gt;&quot;);<br/>&lt;?}?&gt; <br/>function changelocation(id) <br/>{ <br/>document.myform.city.length = 0; <br/>var id=id; <br/>var j; <br/>document.myform.city.options[0] = new Option(&#039;==选择城市==&#039;,&#039;&#039;); <br/>for (j=0;j &lt; onecount2; j++) <br/>{ <br/> &nbsp;if (subcat2[j][1] == id) <br/> &nbsp; { <br/> &nbsp; document.myform.city.options[document.myform.city.length] = new Option(subcat2[j][2], subcat2[j][0]); <br/> &nbsp; } <br/>} <br/>}<br/>&lt;/script&gt; <br/><br/>&lt;!--********************页面表单*************************--&gt;<br/>&lt;form name=&quot;myform&quot; method=&quot;post&quot;&gt; <br/>地址：&lt;select name=&quot;bigClass&quot; onChange=&quot;changelocation(document.myform.bigClass.options[document.myform.bigClass.selectedIndex].value)&quot; size=&quot;1&quot;&gt; <br/>&lt;option selected&gt;请选择省份&lt;/option&gt; <br/> &nbsp; &nbsp; &nbsp; &nbsp;<br/>&lt;?php <br/>$num = count($forum_data);<br/><br/>for($i=0;$i&lt;$num;$i++)<br/>{<br/>?&gt;<br/>&lt;option value=&quot;&lt;?echo $forum_data[$i][&#039;id&#039;];?&gt;&quot;&gt;&lt;?echo $forum_data[$i][&#039;provinceName&#039;];?&gt;&lt;/option&gt; <br/>&lt;? <br/>}<br/>?&gt;<br/>&lt;/select&gt;<br/>&lt;select name=&quot;city&quot; multiple&gt; <br/>&lt;SELECT name=city size=1 id=&quot;city&quot;&gt;<br/>&lt;option selected value=&quot;&quot;&gt;==选择城市==&lt;/option&gt; <br/>&lt;/select&gt;<br/>&lt;/form&gt; <br/>&lt;/body&gt;<br/>&lt;/html&gt; <br/><br/><br/>Tags - <a href="http://www.dzhope.com/tags/%25E4%25B8%258B%25E6%258B%2589%25E8%258F%259C%25E5%258D%2595/" rel="tag">下拉菜单</a> , <a href="http://www.dzhope.com/tags/%25E4%25BA%258C%25E7%25BA%25A7%25E8%2581%2594%25E5%258A%25A8%25E8%258F%259C%25E5%258D%2595/" rel="tag">二级联动菜单</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post/149/#blogcomment2758</link>
<title><![CDATA[[评论] PHP+mysql实现全动态二级联动下拉列表]]></title> 
<author>发 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 26 Apr 2007 10:41:51 +0000</pubDate> 
<guid>http://www.dzhope.com/post/149/#blogcomment2758</guid> 
<description>
<![CDATA[ 
	我按你的这个做了，一级出来了，但二级出不来啊，怎么回事啊，急
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post/149/#blogcomment3012</link>
<title><![CDATA[[评论] PHP+mysql实现全动态二级联动下拉列表]]></title> 
<author>hkingss &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 07 May 2008 07:19:40 +0000</pubDate> 
<guid>http://www.dzhope.com/post/149/#blogcomment3012</guid> 
<description>
<![CDATA[ 
	不错 顶一下！
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post/149/#blogcomment4896</link>
<title><![CDATA[[评论] PHP+mysql实现全动态二级联动下拉列表]]></title> 
<author>kuaile &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 22 Aug 2008 09:10:29 +0000</pubDate> 
<guid>http://www.dzhope.com/post/149/#blogcomment4896</guid> 
<description>
<![CDATA[ 
	我做了 怎么不支持中文读出来的都是问号呀
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post/149/#blogcomment9146</link>
<title><![CDATA[[评论] PHP+mysql实现全动态二级联动下拉列表]]></title> 
<author>caoone &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 25 Nov 2008 06:34:08 +0000</pubDate> 
<guid>http://www.dzhope.com/post/149/#blogcomment9146</guid> 
<description>
<![CDATA[ 
	我的也是按你这种方法做的,之前在DW8时可以用,之后升级到DW8.2后第二级就不能显示了,为什么会这样的呢?
]]>
</description>
</item>
</channel>
</rss>