Print Page | Close Window

Don’t show the subcategories

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5128
Printed Date: 30 March 2026 at 9:50pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Don’t show the subcategories
Posted By: Lucent
Subject: Don’t show the subcategories
Date Posted: 19 August 2003 at 2:16pm

Hi, I have this code I'm trying to modify, but I just cant seem to find a way to get around it , hope someone can help here. 

What I have is part of the code that does the drop down menu of all my categories & subcategories.  I need it just to show only level 1 of my catgories in the drop down menu.

What it shows in the drop down menu right now

Bag-backpack

Bag-clutch

Shoes-sandals

Shoes-boosts

I want it to show only

Bag

Shoes

===========================================

Here is the code I have

=============================================

<% ' get leaf categories from db
mySQL="SELECT idcategory,categoryDesc FROM categories WHERE idparentcategory=1 AND idCategory>1 AND iBTOhide=0 ORDER BY categoryDesc"
set rs=conntemp.execute(mySQL)
%>
<select name="idcategory">
<option value='0'>
<%response.write dictLanguage.Item(Session("language")&"_advSrca_4")%>
</option>
<% Do While NOT rs.EOF
'check to see if catagory has subcategories
strSQL="SELECT idcategory,categoryDesc FROM categories WHERE idParentCategory="& rs("idCategory")
set rs2=server.CreateObject("ADODB.Recordset")
set rs2=conntemp.execute(strSQL)
if rs2.eof then
subVar="1"
Else
do while NOT rs2.eof
strSQL="SELECT idcategory,categoryDesc FROM categories WHERE idCategory="& rs2("idCategory")
dim rs3
set rs3=server.CreateObject("ADODB.Recordset")
set rs3=conntemp.execute(strSQL)
'check to see if catagory has subcategories
strSQL="SELECT idcategory,categoryDesc FROM categories WHERE idParentCategory="& rs3("idcategory")
dim rs4
set rs4=server.CreateObject("ADODB.Recordset")
set rs4=conntemp.execute(strSQL)
if rs4.eof then
subVar3="1"
Else
do while NOT rs4.eof
strSQL="SELECT idcategory,categoryDesc FROM categories WHERE idCategory="& rs4("idCategory")
dim rs5
set rs5=server.CreateObject("ADODB.Recordset")
set rs5=conntemp.execute(strSQL)
'check to see if catagory has subcategories
strSQL="SELECT idcategory,categoryDesc FROM categories WHERE idParentCategory="& rs5("idcategory")
dim rs6
set rs6=server.CreateObject("ADODB.Recordset")
set rs6=conntemp.execute(strSQL)
if rs6.eof then
subVar5="1"
Else
do while NOT rs6.eof
strSQL="SELECT idcategory,categoryDesc FROM categories WHERE idCategory="& rs6("idCategory")
dim rs7
set rs7=server.CreateObject("ADODB.Recordset")
set rs7=conntemp.execute(strSQL)%>
<option value='<%=rs7("idCategory")%>'> <%= rs("categoryDesc") %>
- <%= rs3("categoryDesc") %> - <%= rs5("categoryDesc") %> - <%= rs7("categoryDesc") %></option>
<% rs6.MoveNext
Loop
set rs7=nothing %>
<% End If 'rs6.eof %>
<% If subVar5<>"1" then %>
<% Else %>
<option value='<%=rs5("idCategory")%>'><%= rs("categoryDesc") %>
- <%= rs3("categoryDesc") %> - <%= rs5("categoryDesc") %></option>
<% end if %>
<% rs4.MoveNext
Loop
set rs5=nothing %>
<% End If 'rs4.eof %>
<% If subVar3<>"1" then %>
<% Else %>
<option value='<%=rs3("idCategory")%>'><%= rs("categoryDesc") %>
- <%= rs3("categoryDesc") %></option>
<% end If %>
<% rs2.MoveNext
Loop
set rs3=nothing %>
<% End If 'rs2.eof %>
<% If subVar<>"1" then %>
<% Else %>
<option value='<%=rs("idCategory")%>'><%= rs("categoryDesc") %></option>
<% End If %>
<% subVar="0"
subVar3="0"
subVar5="0"
rs.MoveNext
Loop
set rs1=nothing %>
</select>
<input type="hidden" name="idSupplier" value="10">
</font></td>
</tr>

==============================================

Thanks in advance!!

 




Replies:
Posted By: vshriniwasan
Date Posted: 24 August 2003 at 1:29pm

Is it possible to see it in action, so we can see what exactly you are looking at.



Posted By: peterm
Date Posted: 05 September 2003 at 5:06am

Do you only have two levels of categories? e.g. main category and sub category?

If so, why not have the categories table like this:

CategoryId  Name  OwnerId
--------------------------
1           ;     Shoes      0
2           ;     Bag         0
3           ;     Backpack 2
4           ;     Clutch     2
5           ;     Sandels   1
6           ;     Boosts     1

Then if you only want to display the main categories use the following SQL:

mySQL = "SELECT CategoryId, Name FROM Categories WHERE OwnerId = 0 ORDER BY Name"

This will give you a list of Bag and Shoes, as intended.


Then you can display the subcategories on the following page by retreiving the CategoryId from the form collection and doing a SQL query like

mySQL = "SELECT CategoryId, Name FROM Categories WHERE OwnerId = " & Request.Form("CategoryId")

I'm not if thats what you want - but your ASP file seems over-complicated and very hard to understand - sorry!




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net