數據庫結構
復制代碼 代碼如下:
-- 表的結構 `bigclass`
--
CREATE TABLE `bigclass` (
`bigclassid` int(11) NOT NULL auto_increment,
`bigclassname` varchar(200) collate utf8_unicode_ci NOT NULL,
`sort` int(11) NOT NULL,
`suoshu` int(1) NOT NULL,
PRIMARY KEY (`bigclassid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19 ;
-- 表的結構 `smallclass`
--
CREATE TABLE `smallclass` (
`smallclassid` int(11) NOT NULL auto_increment,
`smallclassname` varchar(200) collate utf8_unicode_ci NOT NULL,
`bigclassid` int(11) NOT NULL,
`sort` int(11) NOT NULL,
PRIMARY KEY (`smallclassid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7 ;
-- 表的結構 `minclass`
--
CREATE TABLE `minclass` (
`minclassid` int(10) NOT NULL auto_increment,
`minclassname` varchar(200) NOT NULL,
`bigclassid` int(10) NOT NULL,
`smallclassid` int(10) NOT NULL,
`sort` int(10) NOT NULL,
PRIMARY KEY (`minclassid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
代碼如下 復制代碼 代碼如下:
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<?
//類別選擇
mysql_select_db($database_lr, $lr);
$sql = "select * from smallclass order by sort";
$result = mysql_query( $sql );
$count = 0;
while($res = mysql_fetch_row($result)){
?>
subcat[<?=$count?>] = new Array("<?=$res[1]?>","<?=$res[4]?>","<?=$res[0]?>");
<?
$count++;
}
?>
onecount=<?php echo $count?>
//聯動函數
function changelocation(bigclassid)
{
document.myform.smallclassid.length = 0;
var bigclassid=bigclassid;
var i;
document.myform.smallclassid.options[0] = new Option('請選擇二級分類','');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == bigclassid)
{
document.myform.smallclassid.options[document.myform.smallclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<?php
mysql_select_db($database_lr, $lr);
$sql2 = "select * from minclass order by sort";
$result2 = mysql_query( $sql2 );
$count2 = 0;
?>
<script language = "JavaScript">
//如果這個數組中含有雙引號則不能使用。即二級和三級類不能含有雙引號
var onecount2;
onecount2=0;
subcat2 = new Array();
<?php
$count2 = 0;
while($res2 = mysql_fetch_row($result2)){
?>
subcat2[<?php echo $count2?>] = new Array("<?php echo $res2[1]?>","<?php echo $res2[3]?>","<?php echo $res2[0]?>");
<?php
$count2++;
}
?>
onecount2=<?php echo $count2?>;
function changelocation2(smallclassid)
{
document.myform.minclassid.length = 0;
var smallclassid=smallclassid;
var j;
document.myform.minclassid.options[0] = new Option('請選擇三級分類','');
for (j=0;j < onecount2; j++)
{
if (subcat2[j][1] == smallclassid)
{
document.myform.minclassid.options[document.myform.minclassid.length] = new Option(subcat2[j][0], subcat2[j][2]);
}
}
}
</script>
<select name="bigclassid" onChange="changelocation(document.myform.bigclassid.options[document.myform.bigclassid.selectedIndex].value)" size="1">
<option selected value="">請指定一級分類</option>
<?
$sql = "select * from bigclass order by sort";
$result = mysql_query( $sql );
while($res = mysql_fetch_row($result)){
?>
<option value="<? echo $res[0]; ?>"><? echo $res[1]?></option>
<? } ?>
</select>
<select name="smallclassid" onChange="changelocation2(document.myform.smallclassid.options[document.myform.smallclassid.selectedIndex].value)" size="1">
<option selected value="">請指定二級分類</option>
</select>
<select name="minclassid" size="1">
<option selected value="">==所有三級分類==</option>
</select>