php mysql三级联动,PHP+mysql实现的三级联动菜单功能示例
本文實例講述了php+mysql實現的三級聯動菜單功能。分享給大家供大家參考,具體如下:
數據庫mysql
-- 數據庫: `student`
--
-- --------------------------------------------------------
--
-- 表的結構 `student`
--
create table `student` (
`id` int(50) not null auto_increment,
`name` varchar(50) collate utf8_unicode_ci not null,
`dept` varchar(50) collate utf8_unicode_ci not null,
`class` varchar(50) collate utf8_unicode_ci not null,
`sex` varchar(50) collate utf8_unicode_ci not null,
`dept_id` int(50) not null,
`class_id` int(50) not null,
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=5 ;
--
-- 導出表中的數據 `student`
--
insert into `student` (`id`, `name`, `dept`, `class`, `sex`, `dept_id`, `class_id`) values
(1, '計算機名字', '計算機工程系', '計061', '男', 1, 11),
(2, '教計名字', '計算機工程系', '教技061', '男', 1, 14),
(3, '管理名字', '管理系', '管理061', '女', 2, 21),
(4, '機械名字', '機械工程系', '自動化061', '男', 3, 31);
index.php代碼:
$link=mysql_connect("localhost","root","") or die("數據庫服務器連接錯誤".mysql_error());
mysql_select_db("student",$link) or die("數據庫訪問錯誤".mysql_error());
mysql_query("set character set gb2312");
mysql_query("set names gb2312");
?>
下拉框連動//二級菜單數組
var subcat = new array();
$i=0;
$sql="select * from student";
$query=mysql_query($sql,$link);
while($arr=mysql_fetch_array($query))
{
echo "subcat[".$i++."] = new array('".$arr["dept_id"]."','".$arr["class"]."','".$arr["class_id"]."');\n";
}
?>
//三級菜單數組
var subcat2 = new array();
$i=0;
$sql="select * from student";
$query=mysql_query($sql,$link);
while($arr=mysql_fetch_array($query))
{
echo "subcat2[".$i++."] = new array('".$arr["class_id"]."','".$arr["class"]."','".$arr["name"]."');\n";
}
?>
function changeselect1(locationid)
{
document.form1.s2.length = 0;
document.form1.s2.options[0] = new option('22請選擇22','');
for (i=0; i
{
if (subcat[i][0] == locationid)
{
document.form1.s2.options[document.form1.s2.length] = new option(subcat[i][1], subcat[i][2]);
}
}
}
function changeselect2(locationid)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new option('33請選擇33','');
for (i=0; i
{
if (subcat2[i][0] == locationid)
{
document.form1.s3.options[document.form1.s3.length] = new option(subcat2[i][2], subcat2[i][0]);
}
}
}
三級聯動演示:
--請選擇--
計算機工程系
管理系
機械工程系
--請選擇--
--請選擇--
希望本文所述對大家php程序設計有所幫助。
希望與廣大網友互動??
點此進行留言吧!
總結
以上是生活随笔為你收集整理的php mysql三级联动,PHP+mysql实现的三级联动菜单功能示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iPhone 15 Pro等四款苹果手机
- 下一篇: mysql 视图触发器,MySql视图触