读书人

大类和小类都放在一张表里面,怎样将大

发布时间: 2012-02-20 21:18:24 作者: rapoo

大类和小类都放在一张表里面,怎样将大类和小类在select表单里动态关联起来?
我的大类和小类都放在一张表里面,怎样将大类和小类在select表单里动态关联起来?
我以前是将大类和小类表单独分开,放在两张表里面,用下面的方法没有错误,但这次我把大类和小类放在一张表里面后,用下面的方法一直关联不起来.
说名:
类别表:Class(一级和二级都放在这张表里面)
主要有这几个字段:ID,Type,ParentID,ClassName
说明:ID为自动编号,Type=1表示一级分类,type=2表示二级分类,ParentID表示上一级的ID(这里只有两级),目的是让一级和二级关联. ClassName为类别名称.
请高手帮忙,看看下面哪里出了问题??????应该怎样解决???????
解决马上散分!!!!!!!!!!!!!!!!!!!!!!!!!!!

<!--#include file= "../include/sqlconn.asp "-->
<%
set rs3=server.createobject( "adodb.recordset ")
strsql= "select * from Class where type=2 "
rs3.open strsql,conn,3,3
if rs3.eof and rs3.bof then
response.write "请先添加小类! "
else
%>
<html>
<head>
<title> 添加图片 </title>
<link href= "inc/pic.css " rel= "stylesheet " type= "text/css ">
<script language= "JavaScript ">
function save()
{
if(!CheckIsNull(form2.TitleName, "请填写标题名称! ")) return false;
if(!CheckIsNull(form2.Tag, "请填写关键字! ")) return false;
if(!CheckIsNull(form2.SmallClassID, "请选择小类名称! ")) return false;
if(!CheckIsNull(form2, "请选择大类名称! ")) return false;
document.form2.submit();
}
</script>

<script language= "javascript ">
function PreviewImg(obj){
var div = document.getElementById( "previewDiv ");
if(obj.value== " ")
{div.removeChild(div.firstChild);
return
}
if(div.childNodes.length> 0){
div.firstChild.src=obj.value;
}
else{
var img = document.createElement( "img ");
img.width= "160 ";
img.height= "110 ";
img.border=0;
img.src=obj.value;
div.appendChild(img);
}
}
</script>

<script language = "JavaScript ">
var onecount;
subcat = new Array();
<%
count = 0
do while not rs3.eof


%>
subcat[ <%=count%> ] = new Array( " <%= trim(rs3( "ClassName "))%> ", " <%= trim(rs3( "ParentID "))%> ", " <%= trim(rs3( "id "))%> ");
<%
count = count + 1
rs3.movenext
loop
rs3.close
%>
onecount= <%=count%> ;

function changelocation(locationid)
{
document.form2.SmallClassID.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.form2.SmallClassID.options[document.form2.SmallClassID.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
function closedlg()
{
window.parent.opener.location.reload();
window.close() ;
}
</script>
<%
end if
%>
<base target= "mz520_main ">
</head>
<body topmargin= "0 " leftmargin= "0 " bgcolor= "#EEF3F7 " onload= "form2.TitleName.focus(); ">
<table border= "0 " width= "46% " id= "table1 " height= "353 " align= "center ">
<tr>
<td width= "460 " bgcolor= "#eef3f7 ">
<form name=form2 method= "post " action= "SaveTitle_Add.asp " enctype= "multipart/form-data " >
<table border= "0 " width= "458 " id= "table2 " height= "165 " align= "center ">
<tr>
<td height= "20 " align= "center ">
</td>
<td height= "20 " align= "center " width= "360 "> <img border= "0 " src= "img/btn_img03.gif " width= "142 " height= "49 ">
</td>
</tr>
<tr>


<td width= "80 " align= "right " height= "48 "> 标题:
</td>
<td height= "48 " align= "left " width= "360 ">
<input name= "TitleName " size= "38 " class=inbox01 >
</td>
</tr>
<tr>
<td width= "80 " align= "right "> 标签: </td>
<td align= "left " width= "360 ">
<input name= "Tag " size= "43 " class=inbox01>
</td>
</tr>
<tr>
<td width= "80 " align= "right "> 分类:
</td>
<td align= "left " width= "360 ">
<%
set rs=server.createobject( "adodb.recordset ")
sql = "select * from Class where type=1 order by ClassOrder desc "
rs.open sql,conn,3,3
if rs.eof and rs.bof then
response.write "没有类别,请先添加类别! "
else
%>
大类: <select name= "BigClassID " size= "1 ">
<option selected value= " <%=trim(rs( "ID "))%> "> <%=trim(rs( "ClassName "))%> </option>
<%
dim selclass
selclass=rs( "ID ")
rs.movenext
do while not rs.eof
%>
<option selected value= " <%=trim(rs( "ID "))%> "> <%=trim(rs( "ClassName "))%> </option>
<%
rs.movenext
loop


end if
rs.close
set rs=nothing
%>
</select>
小类: <select name= "SmallClassID ">
<%
set rs2=server.createobject( "adodb.recordset ")
strsql= "select * from Class where type=2 and parentid= ' " & selclass & " ' "
rs2.open strsql,conn,3,3
if not(rs2.eof and rs2.bof) then
%>
<option value= " <%=rs2( "ID ")%> "> <%=rs2( "ClassName ")%> </option>
<%
rs2.movenext
do while not rs2.eof
%>
<option value= " <%=rs2( "ID ")%> "> <%=rs2( "ClassName ")%> </option>
<%
rs2.movenext
loop
end if
rs2.close
set rs2=nothing
%>
</select>
</td>
</tr>
<tr>
<td width= "80 " align= "right "> 封面:
</td>
<td align= "left " width= "360 ">
<input name= "Titlepic " size= "32 " class=inbox01 type= "file " value= " " onchange= "PreviewImg(this); " style= "background-color: #FFCC66 ">
</td>
</tr>
<tr>
<td width= "80 " align= "right "> 图片:
</td>
<td align= "left " width= "87% ">
<div style= "width:138px;height:116px;border:1px solid #aaaaaa;overflow:auto " id= "previewDiv "> <img border= "0 " src= "img/nophoto.gif " width= "136 " height= "113 "> </div>


</td>
</tr>
<tr>
<td width= "80 " align= "right "> 简介:
</td>
<td align= "left " width= "360 ">
<TEXTAREA name=Content rows=6 cols=43 style= "border: 1px solid #5594B9 "> </TEXTAREA>
</td>
</tr>
</table>
<p align= "center ">
<input type= "submit " value= "提交 " name= "btn1 " class=btn >
<input type= "button " value= "关闭 " onclick= "closedlg(); " name= "btn2 " class=btn >
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<%
call closeconn
%>

[解决办法]
默认调用type=1

然后通过Ajax去实现二级菜单的显示就可以了。
[解决办法]
太长了,网上随便找个二级联动的demo看一下就明白了.

读书人网 >ASP

热点推荐