PHP树形菜单一次展开一个子项目


<?phprequire('../Connections/lr.php');?>
<?phprequire('pageconfig.php');
$htmlcatalogue="html/";//生成文件所在的目录
?>
<SCRIPTlanguage=JavaScript>
var__cc_uid="shenglu";
</SCRIPT>
<SCRIPTtype=text/javascript>
varpersistmenu="yes"//"yes"or"no".MakesureeachSPANcontentcontainsanincrementingIDstartingat1(id="sub1",id="sub2",etc)
varpersisttype="sitewide"//enter"sitewide"formenutopersistacrosssite,"local"forthispageonly

if(document.getElementById){//DynamicDrive.comchange
document.write('<styletype="text/css">\n')
document.write('.submenu{display:none;}\n')
document.write('</style>\n')
}

functionSwitchMenu(obj){
if(document.getElementById){
varel=document.getElementById(obj);
varar=document.getElementById("masterdiv").getElementsByTagName("tr");//DynamicDrive.comchange
if(el.style.display!="block"){//DynamicDrive.comchange
for(vari=0;i<ar.length;i++){
if(ar[i].className=="submenu")//DynamicDrive.comchange
ar[i].style.display="none";
}
el.style.display="block";
}else{
el.style.display="none";
}
}
}

functionget_cookie(Name){
varsearch=Name+"="
varreturnvalue="";
if(document.cookie.length>0){
offset=document.cookie.indexOf(search)
if(offset!=-1){
offset+=search.length
end=document.cookie.indexOf(";",offset);
if(end==-1)end=document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset,end))
}
}
returnreturnvalue;
}

functiononloadfunction(){
if(persistmenu=="yes"){
varcookiename=(persisttype=="sitewide")?"switchmenu":window.location.pathname
varcookievalue=get_cookie(cookiename)
if(cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

functionsavemenustate(){
varinc=1,blockid=""
while(document.getElementById("sub"+inc)){
if(document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
varcookiename=(persisttype=="sitewide")?"switchmenu":window.location.pathname
varcookievalue=(persisttype=="sitewide")?blockid+";path=/":blockid
document.cookie=cookiename+"="+cookievalue
}

if(window.addEventListener)
window.addEventListener("load",onloadfunction,false)
elseif(window.attachEvent)
window.attachEvent("onload",onloadfunction)
elseif(document.getElementById)
window.onload=onloadfunction

if(persistmenu=="yes"&&document.getElementById)
window.onunload=savemenustate

</SCRIPT>

<STYLEtype=text/css>BODY{
FONT-SIZE:12px;COLOR:#666666
}
TD{
FONT-SIZE:12px;COLOR:#666666
}
TH{
FONT-SIZE:12px;COLOR:#666666
}
BODY{
MARGIN:0px;BACKGROUND-COLOR:#f7f7f7
}
.xian{
BORDER-RIGHT:#bbbbbb1pxsolid;BORDER-LEFT:#bbbbbb1pxsolid
}
.sousuo{
BORDER-RIGHT:#6666661pxsolid;BORDER-TOP:#6666661pxsolid;FONT-SIZE:12px;BORDER-LEFT:#6666661pxsolid;COLOR:#ff0000;BORDER-BOTTOM:#6666661pxsolid
}
.sousuoboot{
FONT-SIZE:12px;COLOR:#ffffff;BORDER-TOP-STYLE:none;BORDER-RIGHT-STYLE:none;BORDER-LEFT-STYLE:none;BACKGROUND-COLOR:#dc211a;BORDER-BOTTOM-STYLE:none
}
.form{
PADDING-BOTTOM:0px;MARGIN:0px;PADDING-TOP:12px
}
.imgnews{
HEIGHT:100px
}
.news{
PADDING-TOP:10px
}
A:link{
COLOR:#666666;TEXT-DECORATION:none
}
A:visited{
COLOR:#666666;TEXT-DECORATION:none
}
A:hover{
COLOR:#ff0000;TEXT-DECORATION:underline
}
A:active{
COLOR:#ff0000;TEXT-DECORATION:none
}
.mainbg{
BACKGROUND-POSITION:50%top;BACKGROUND-IMAGE:url(images/2009.gif);BACKGROUND-REPEAT:no-repeat;BACKGROUND-COLOR:#ffffff
}
.more{
MARGIN-TOP:11px;MARGIN-LEFT:178px
}
</STYLE>

<STYLEtype=text/css>.menutitle{
PADDING-RIGHT:2px;PADDING-LEFT:2px;FONT-WEIGHT:bold;MARGIN-BOTTOM:5px;PADDING-BOTTOM:2px;MARGIN-LEFT:auto;WIDTH:200px;CURSOR:pointer;COLOR:#000000;MARGIN-RIGHT:auto;PADDING-TOP:2px
}
.submenu{
MARGIN-BOTTOM:0.5em
}
</STYLE>


<divalign="center"class="cata">Browsebycategory</div>
<TABLEid=masterdivcellSpacing=2cellPadding=0width="100%"align=centerborder=0>
<TBODY>
<?phpmysql_select_db($database_lr,$lr);
$query=mysql_query("SELECT*FROMbigclassorderbysort");
$j=0;
while($row=mysql_fetch_array($query))
{$j=$j+1;
$bigclassid=$row['bigclassid'];
$bigclassname_leftmenu=$row['bigclassname'];
if($htmlname==1){
$bigclass_htmlname_leftmenu=$bigclassname_leftmenu;//大类名称
if(substr_count($bigclass_htmlname_leftmenu,"")>0){
$bigclass_htmlname_leftmenu=str_replace("","-",$bigclass_htmlname_leftmenu);
}
}
if($htmlname==0){
$bigclass_htmlname_leftmenu=$bigclassid;
}
?>

<TRclass=menutitleonClick="SwitchMenu('sub<?phpecho$j?>')">
<TD><imgsrc="../images/arrow.gif"style="margin-bottom:1px"/><Spanclass="bigclassname"><?phpecho$row['bigclassname']?></Span></TD></TR>
<Tr>
<TRclass=submenuid=sub<?phpecho$j?>>
<TD>



<TABLEcellSpacing=2cellPadding=0width="100%"border=0>

<TBODY>
<?php
mysql_select_db($database_lr,$lr);
$query_small=mysql_query("SELECT*FROMsmallclasswherebigclassid='$bigclassid'orderbysort");
while($rs=mysql_fetch_array($query_small))


{
$smallclassid_small_leftmenu=$rs['smallclassid'];
$smallclassname_small=$rs['smallclassname'];//小类名称

if($htmlname==1){
$smallclass_htmlname=$smallclassname_small;
if(substr_count($smallclass_htmlname,"")>0){
$smallclass_htmlname=str_replace("","-",$smallclass_htmlname);
}
}
if($htmlname==0){
$smallclass_htmlname=$smallclassid_small_leftmenu;
}

?>
<tr><Td>&nbsp;&nbsp;&nbsp;<imgsrc="../images/arrow.gif"style="margin-bottom:0px"/><ahref="<?phpecho"../".$htmlcatalogue."".$bigclass_htmlname_leftmenu."_".$smallclass_htmlname."_page_1.html"?>"class="smallclasslink"><?phpecho$rs['smallclassname']?></a></Td></tr>
<?php
}?>
</TBODY></TABLE>



</TD></TR>
<?php
}?></TBODY></TABLE>
数据库为mysql,表结构如下,bigclass 字段为bigclassid bigclassname ,小类为smallclass字段为smallclassid,smallclassid

你可能感兴趣的:(JavaScript,PHP,mysql,css,J#)