判断一级分类,二级分类

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_37815596/article/details/81583986

1.

效果图如下:

<?php echo "<pre>";print_r($接口变量名)?>

根据如下代码,将一级分类和二级分类循环出来,然后为循环出来的分类写样式

<ul class="clearfix">
                  <foreach name="category" item="value">
                    <?php if ($value['upid']=='0'): ?>
                      <li>
                         <a href="/product/list/id/{$value.id}">
                             <img src="{$value.cp_description}">
                             <p style="text-align: left;">{$value.name}</p>
                         </a>
                         <ul class="secondul">
                           <?php foreach ($category as $key => $val): ?>
                             <?php if ($val['upid']==$value['id']): ?>
                                <li>
                                  <a href="/product/list/id/{$val.id}">
                                    <p>{$val.name}</p>
                                  </a>
                                </li>
                             <?php endif ?>
                           <?php endforeach ?>
                         </ul>
                      </li>
                    <?php endif ?>
                    </if>
                  </foreach>
               </ul>

2.导航栏

<ul class="clearfix">
                                <foreach name="value.child" item="val">
                                     <li>
                                        <a href="{$val.link}"><i class="fa fa-angle-right" aria-hidden="true"></i> {$val.name}</a>
                                        <ul class="navul">
                                            <foreach name="val.child" item="va">
                                    
                                                 <li><a href="{$va.link}"><i class="fa fa-angle-right" aria-hidden="true"></i> {$va.name}</a></li>
                                            </foreach>  
                                        </ul>
                                     </li>
                                </foreach>                     
                            </ul>

 

展开阅读全文

Struts2的iterator如何获取一级分类和对应的二级分类

05-20

我写了一个图书管理模块,图书分类为一级分类,和二级分类rn比如:rn一级分类有 小说 和计算机 两大类,小说又包括恐怖,言情等二级分类。rnrn现在有两个类Fathertype,Subtype, 分别代表一级分类和二级分类,其中Fathertype类里又有一个list型rn的Subtype的属性。rn rn我现在想在页面里显示出如下格式:应该怎么写rnrn小说rn恐怖 言情rn计算机rnC++ javarnrnrnaction传给页面的值是fathertypernrn public List fathertype;rn rn public List getFathertype()rn rn return this.fathertype;rn rn rn public void setFathertype(List fathertype)rn rn this.fathertype=fathertype;rn rnrnrn public String execute() throws Exception rn rn Fathertype f1=new Fathertype();rn f1.setId(1);rn f1.setTypename("小说");rn Subtype s1=new Subtype();rn s1.setFid(1);rn s1.setId(1);rn s1.setSubypename("言情");rn rn Subtype s2=new Subtype();rn s2.setFid(1);rn s2.setId(2);rn s2.setSubypename("恐怖");rn rn List l=new ArrayList();rn l.add(s1);rn l.add(s2);rn rn f1.setSubtype(l);rn rn Fathertype f2=new Fathertype();rn f2.setId(2);rn f2.setTypename("计算机");rn Subtype s3=new Subtype();rn s3.setFid(2);rn s3.setId(3);rn s3.setSubypename("JAVA");rn rn Subtype s4=new Subtype();rn s4.setFid(2);rn s4.setId(4);rn s4.setSubypename("C+");rn rn List l2=new ArrayList();rn l.add(s3);rn l.add(s4);rn rn f2.setSubtype(l2); rn rn rn List f=new ArrayList();rn f.add(f1);rn f.add(f2);rn rn fathertype=f;rn rn rn return SUCCESS;rnrn rnrnrn我前台页面这样写rnrn rn rn rn rnrnrn但是显示的是rn小说rn恐怖 言情rnC++ javarn计算机rnrn如何才能正确显示呢 论坛

【求助】编辑信息时如何实现点击二级分类时只显示一级分类对应的二级分类

08-16

说明:数据库相关表和字段rn一级分类目录表 jle_class1 字段有 id,class1name,Class1Sort rn二级分类目录表 jle_class2字段有 id,class2name,Class1 ,Class2Sort,其中Class1索引一级分类IDrn信息文章表 jle_info 字段有id,in_class1,in_class2等,其中in_class1索引一级分类ID,和二级分类Class1 ,Class2索引二级分类IDrn问题:点击二级分类时不能只显示一级分类对应的二级分类,而出现所有二级分类,点击一级分类后可以只显示对应的二级分类rnrn目的:实现点击二级分类时只显示一级分类对应的二级分类,谢谢!rnrnrnrnrnrnrnrn<%rnAction=CheckStr(trim(request("Action")))rnif Action="Add" thenrn Call Add()rnelseif Action="Del" thenrn Call Del()rnelseif Action="Del2" thenrn Call Del2()rnelse rn Call Edit()rnend if rnrnrnSub Add()rnID=CheckNum(Request("ID"))rnIN_Class1=CheckStr(Trim(Request("Class1Name")))rnIN_Class2=CheckStr(Trim(Request("Class2Name")))rnIN_Title=CheckStr(Trim(Request("Title")))rnIN_Area=CheckStr(Trim(Request("Area")))rnIN_JiaGe=CheckStr(Trim(Request("JiaGe")))rnIN_Name=CheckStr(Trim(Request("Name")))rnIN_Tel=CheckStr(Trim(Request("Tel")))rndays=CheckStr(Trim(Request("Sj")))rnIN_QQ=CheckStr(Trim(Request("QQ")))rnIN_Email=CheckStr(Trim(Request("Email")))rnIN_DiZhi=CheckStr(Trim(Request("DiZhi")))rnIN_Images=CheckStr(Trim(Request("Images")))rnIN_ConTent=HTMLDecode(Request("ConTent"))rnIf IN_Class1="" Thenrnresponse.Write(" ")rnresponse.Endrnelseif IN_Class2="" Thenrnresponse.Write(" ")rnresponse.End rnelseif IN_Title="" Thenrnresponse.Write(" ")rnresponse.End rnelseif len(IN_Title)>50 thenrnresponse.Write(" ")rnresponse.Endrnelseif IN_Name="" thenrnresponse.Write(" ")rnresponse.End rnelseif IN_ConTent="" thenrnresponse.Write(" ")rnresponse.Endrnelsernset rsc=server.CreateObject("ADODB.RECORDSET")rnsql="select * from jle_info where id="&IDrnrsc.open sql,conn,1,3 rnrsc("IN_Class1")=IN_Class1rnrsc("IN_Class2")=IN_Class2rnrsc("IN_Title")=IN_Titlernrsc("IN_Area")=IN_Arearnrsc("IN_ConTent")=IN_ConTentrnIF IN_JiaGe<>"" Thenrnrsc("IN_JiaGe")=IN_JiaGernend ifrnrsc("IN_Name")=IN_NamernIF IN_Tel<>"" Thenrnrsc("IN_Tel")=IN_Telrnend ifrnIF IN_QQ<>"" Thenrnrsc("IN_QQ")=IN_QQrnend ifrnIF IN_Email<>"" Thenrnrsc("IN_Email")=IN_Emailrnend ifrnIF IN_DiZhi<>"" Thenrnrsc("IN_DiZhi")=IN_DiZhirnend ifrnIF IN_Images<>"" Thenrnrsc("IN_Images")=IN_Imagesrnend ifrnrsc.updaternrsc.closernSet rsc=nothingrnresponse.redirect("Admin_html.asp?Action=3&ID="&ID&"") rnend ifrnEnd SubrnrnrnSub Del()rn set rs=server.CreateObject("ADODB.RECORDSET")rn sql="select * from jle_info where IN_Html = '"&request("IN_Html")&"'"rn rs.open sql,conn,1,3 rn dh_user=rs("in_user")rn if rs("in_User")<>"" thenrn set rsC=server.CreateObject("ADODB.RECORDSET")rn sqlc="select * from jle_User where DH_User='" & DH_User & "'"rn rsC.open sqlc,conn,1,3 rn DH_Money=rsc("DH_Money")rn username=rsc("DH_User")rn set rst=server.CreateObject("ADODB.RECORDSET")rn sql1="select * from jifen"rn rst.open sql1,conn,1,3rn rst.addnewrn rst("jieyu")=DH_Money-10rn rst("jifen")="-10"rn rst("shijian")="广告或垃圾信息被删除"rn rst("user")=usernamern rst.updatern rst.closern set rst=nothingrn rsc("DH_Money")=rsc("DH_Money")-10rn rsc.updatern rsc.closern set rsc=nothingrn end ifrn rs.closern set rs=nothingrnSet fso = Server.CreateObject("Scripting.FileSystemObject")rnfso.DeleteFile server.mappath("../InfoList")&"\"&request("IN_Html"),true '此处需要服务器支持FSO删除权限!rnsql="Delete From jle_info where IN_Html = '"&request("IN_Html")&"'"rnconn.Execute(sql)rn rnCall Alert("信息删除成功!","Admin_Info.Asp")rnEnd SubrnrnrnSub Del2()rnid=trim(request("id"))rnif id="" thenrnresponse.Write(" ")rnelsernset rs=server.CreateObject("ADODB.RECORDSET")rnArrayID = Split(id,",")rn For i=0 TO ubound(ArrayID)rn Conn.Execute ("Delete From [jle_info] Where id = " & CInt(ArrayID(i)))rn Nextrncall Alert("删除成功!","Admin_Info.Asp")rnrs.closernset rs=nothingrnend ifrnEnd SubrnrnrnSub Edit()rnID=CheckStr(trim(request("ID")))rnset rs=server.CreateObject("ADODB.RECORDSET")rnsql="select * from jle_info where id="&IDrnrs.open sql,conn,1,1rnif rs.eof and rs.bof thenrn response.Write(" ")rn response.Endrnend ifrn%>rnrnrn rn rn 信息编辑rnrn rnrn rn rn rn 编辑信息rn rn rn rn 栏目分类:rn rn<%rnset rsa=server.createobject("adodb.recordset")rnsql = "select * from jle_class2 order by Class2Sort asc"rnrsa.open sql,conn,1,1rn%> rn<%rnsql = "select * from jle_class1 order by Class1Sort asc"rnrsa.open sql,conn,1,1rnif rsa.eof and rsa.bof thenrnresponse.write "请先添加栏目。"rnresponse.endrnelsern%>rnrnrn一级分类rn<%do while not rsa.eofrn%>rn" <%if rs("IN_Class1")=trim(rsa("id")) then %>selected<% end if %>><%=trim(mid(rsa("Class1Name"),1,4))%>rn<%rnrsa.movenextrnlooprnend ifrnrsa.closern%>rnrnrn二级分类rnrn* 地区: 全市区 rn<%rnset rsCity=server.createobject("adodb.recordset")rnsqlc="select * from jle_area order by AreaSort asc"rnrsCity.open sqlc,connstr,1,1 rndo while not rsCity.eof rn%>rn" <%if rs("IN_Area")=rsCity("Area") then %>selected<% end if %>><%=rsCity("Area")%>rn<%rnrsCity.movenextrnlooprn%>rn<%rsCity.closernset rsCity=nothingrn%> rn rn rn 信息标题:rn "> rn * rn rn rn 联系人:rn rn " type="text" size="16" maxlength="20">rn 电话:">rn rn rn QQ:rn " type="text" size="16" maxlength="15">rn Email:" type="text" size="30" maxlength="300">rn rn rn 联系地址:rn " type="text" size="40" maxlength="40">rn name=ID> rn rn rn 文章内容:rn <%=rs("IN_ConTent")%>rnrn rn 图片地址:rn ">rn rn rn rn rn rn rn rn rnrn<%rs.closernset rs=nothingrnEnd Subrn%> 论坛

没有更多推荐了,返回首页