ASP recursion issue
- Rabid Dog
- Web Master


- Joined: May 21, 2004
- Posts: 3229
- Loc: South Africa
- Status: Offline
Problem: I need to create a tree view (navigation) from a database. The tree has to respond to javascript so it must be well formatted HTML.
The class i have written is below. the problem is that every entry that comes from the db is being placed inside a unordered list tag so the javascript only hides the one item (or the first instance it comes across)
I thought I had a solution but had to finish a different job and now I have lost the plot completly.
Anmyone know of any example scripts or resources please let me know or if you have a solution even better
Thanks guys
The class i have written is below. the problem is that every entry that comes from the db is being placed inside a unordered list tag so the javascript only hides the one item (or the first instance it comes across)
I thought I had a solution but had to finish a different job and now I have lost the plot completly.
Anmyone know of any example scripts or resources please let me know or if you have a solution even better
Code: [ Select ]
<%
Class recursion
Private DBLink ' DB Reference
Public strMasterRow ' row Containg pk - to be removed
Public strDisplayRow ' Row name to be displayed
Public strIDRow ' row containing PK
Public strTable ' table name
Public strParentRow ' Parent row name
Public strParentClass ' Display Class
Public strChildClass ' Display Class
Public strOut 'String to be displayed
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
Set DBLink = openDB() ' External function
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Terminate()
closeDatabase(DBLink) ' external function
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub getTree(parentID)
Dim rsData
Dim strSql
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
Set rsData = DBLink.Execute(strSql)
While Not rsData.Eof
strOut = strOut & "<ul>"
strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
call getTree(1,rsData(strIDRow),0)
strOut = strOut & "</ul>"
rsData.MoveNext
Wend
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function checkParent(parentID)
Dim rsData, strSql
strSql = "SELECT " &strParentRow& " FROM " &strTable& " WHERE " &strParentRow& " = '" &parentID& "'"
Set rsData = DBLink.Execute(strSql)
If Not rsData.Eof then
checkParent = True
Else
checkParent = False
End If
rsData.Close
Set rsData = Nothing
End Function
End Class
%>
Class recursion
Private DBLink ' DB Reference
Public strMasterRow ' row Containg pk - to be removed
Public strDisplayRow ' Row name to be displayed
Public strIDRow ' row containing PK
Public strTable ' table name
Public strParentRow ' Parent row name
Public strParentClass ' Display Class
Public strChildClass ' Display Class
Public strOut 'String to be displayed
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
Set DBLink = openDB() ' External function
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Terminate()
closeDatabase(DBLink) ' external function
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub getTree(parentID)
Dim rsData
Dim strSql
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
Set rsData = DBLink.Execute(strSql)
While Not rsData.Eof
strOut = strOut & "<ul>"
strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
call getTree(1,rsData(strIDRow),0)
strOut = strOut & "</ul>"
rsData.MoveNext
Wend
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function checkParent(parentID)
Dim rsData, strSql
strSql = "SELECT " &strParentRow& " FROM " &strTable& " WHERE " &strParentRow& " = '" &parentID& "'"
Set rsData = DBLink.Execute(strSql)
If Not rsData.Eof then
checkParent = True
Else
checkParent = False
End If
rsData.Close
Set rsData = Nothing
End Function
End Class
%>
- <%
- Class recursion
- Private DBLink ' DB Reference
- Public strMasterRow ' row Containg pk - to be removed
- Public strDisplayRow ' Row name to be displayed
- Public strIDRow ' row containing PK
- Public strTable ' table name
- Public strParentRow ' Parent row name
- Public strParentClass ' Display Class
- Public strChildClass ' Display Class
- Public strOut 'String to be displayed
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub Class_Initialize()
- Set DBLink = openDB() ' External function
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub Class_Terminate()
- closeDatabase(DBLink) ' external function
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Public Sub getTree(parentID)
- Dim rsData
- Dim strSql
- strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
- Set rsData = DBLink.Execute(strSql)
- While Not rsData.Eof
- strOut = strOut & "<ul>"
- strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
- call getTree(1,rsData(strIDRow),0)
- strOut = strOut & "</ul>"
- rsData.MoveNext
- Wend
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Function checkParent(parentID)
- Dim rsData, strSql
- strSql = "SELECT " &strParentRow& " FROM " &strTable& " WHERE " &strParentRow& " = '" &parentID& "'"
- Set rsData = DBLink.Execute(strSql)
- If Not rsData.Eof then
- checkParent = True
- Else
- checkParent = False
- End If
- rsData.Close
- Set rsData = Nothing
- End Function
- End Class
- %>
Thanks guys
Watch me grow
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
June 10th, 2004, 2:58 am
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
Well as I got a personal invite, I thought I would come look (especially as I owe you one!).
TBH I'm not sure what the problem is. Is it a problem with the ASP or the javascript?
Thats the line that is confusing me.
Do you need a good quality expanding/collapsing treeview javascript? That I can sort you out with, and it will be a very good one
Can you clarify the question?
TBH I'm not sure what the problem is. Is it a problem with the ASP or the javascript?
Quote:
the problem is that every entry that comes from the db is being placed inside a unordered list tag so the javascript only hides the one item (or the first instance it comes across)
Thats the line that is confusing me.
Do you need a good quality expanding/collapsing treeview javascript? That I can sort you out with, and it will be a very good one
Can you clarify the question?
CSS website design tutorials
- Rabid Dog
- Web Master


- Joined: May 21, 2004
- Posts: 3229
- Loc: South Africa
- Status: Offline
If you could supply me with a quality tree script I would appreciate that.
The output for the ASP is something to effect of
now when I run a js against this code (item 1 being the parent) the only one that will display is sub item one
I have tried wrapping them in a span layer but it generates duplicate id's as well. been stuck here for three days
The output for the ASP is something to effect of
Code: [ Select ]
item one
<ul id="item1"><li>sub item one</li></ul>
<ul id="item1"><li>sub item two</li>
<ul id="subitem2">
<li>sub sub item one</li>
<li>sub sub item two</li>
</ul>
</ul>
<ul id="item1"><li>sub item one</li></ul>
<ul id="item1"><li>sub item two</li>
<ul id="subitem2">
<li>sub sub item one</li>
<li>sub sub item two</li>
</ul>
</ul>
- item one
- <ul id="item1"><li>sub item one</li></ul>
- <ul id="item1"><li>sub item two</li>
- <ul id="subitem2">
- <li>sub sub item one</li>
- <li>sub sub item two</li>
- </ul>
- </ul>
now when I run a js against this code (item 1 being the parent) the only one that will display is sub item one
I have tried wrapping them in a span layer but it generates duplicate id's as well. been stuck here for three days

Watch me grow
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
Ok I just looked closer at the ASP and it looks to me like you are getting something like this output i the html
where you should be getting:
for a proper, unordered, nested list, you should be aiming to create:
I think this section:
should look more like:
So that the ul's have a block of li's inside them not just single li's.
That is definately the first step I think.
Code: [ Select ]
<ul><li>Item Text here</li></ul>
<ul><li>Item Text here</li></ul>
<ul><li>Item Text here</li></ul>
<ul><li>Item Text here</li></ul>
<ul><li>Item Text here</li></ul>
<ul><li>Item Text here</li></ul>
<ul><li>Item Text here</li></ul>
- <ul><li>Item Text here</li></ul>
- <ul><li>Item Text here</li></ul>
- <ul><li>Item Text here</li></ul>
- <ul><li>Item Text here</li></ul>
where you should be getting:
Code: [ Select ]
<ul>
<li>Item Text here</li>
<li>Item Text here</li>
<li>Item Text here</li>
<li>Item Text here</li>
</ul>
<li>Item Text here</li>
<li>Item Text here</li>
<li>Item Text here</li>
<li>Item Text here</li>
</ul>
- <ul>
- <li>Item Text here</li>
- <li>Item Text here</li>
- <li>Item Text here</li>
- <li>Item Text here</li>
- </ul>
for a proper, unordered, nested list, you should be aiming to create:
Code: [ Select ]
<ul>
<li>Item Text here</li>
<li>Parent Item Text here
<ul>
<li>Item Text here</li>
<li>Item Text here</li>
<li>Item Text here</li>
<li>Item Text here</li>
</ul>
</li>
<li>Item Text here</li>
<li>Item Text here</li>
</ul>
<li>Item Text here</li>
<li>Parent Item Text here
<ul>
<li>Item Text here</li>
<li>Item Text here</li>
<li>Item Text here</li>
<li>Item Text here</li>
</ul>
</li>
<li>Item Text here</li>
<li>Item Text here</li>
</ul>
- <ul>
- <li>Item Text here</li>
- <li>Parent Item Text here
- <ul>
- <li>Item Text here</li>
- <li>Item Text here</li>
- <li>Item Text here</li>
- <li>Item Text here</li>
- </ul>
- </li>
- <li>Item Text here</li>
- <li>Item Text here</li>
- </ul>
I think this section:
Code: [ Select ]
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
Set rsData = DBLink.Execute(strSql)
While Not rsData.Eof
strOut = strOut & "<ul>"
strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
call getTree(1,rsData(strIDRow),0)
strOut = strOut & "</ul>"
rsData.MoveNext
Wend
Set rsData = DBLink.Execute(strSql)
While Not rsData.Eof
strOut = strOut & "<ul>"
strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
call getTree(1,rsData(strIDRow),0)
strOut = strOut & "</ul>"
rsData.MoveNext
Wend
- strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
- Set rsData = DBLink.Execute(strSql)
- While Not rsData.Eof
- strOut = strOut & "<ul>"
- strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
- call getTree(1,rsData(strIDRow),0)
- strOut = strOut & "</ul>"
- rsData.MoveNext
- Wend
should look more like:
Code: [ Select ]
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
Set rsData = DBLink.Execute(strSql)
strOut = strOut & "<ul>"
While Not rsData.Eof
strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
call getTree(1,rsData(strIDRow),0)
rsData.MoveNext
Wend
strOut = strOut & "</ul>"
Set rsData = DBLink.Execute(strSql)
strOut = strOut & "<ul>"
While Not rsData.Eof
strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
call getTree(1,rsData(strIDRow),0)
rsData.MoveNext
Wend
strOut = strOut & "</ul>"
- strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
- Set rsData = DBLink.Execute(strSql)
- strOut = strOut & "<ul>"
- While Not rsData.Eof
- strOut = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
- call getTree(1,rsData(strIDRow),0)
- rsData.MoveNext
- Wend
- strOut = strOut & "</ul>"
So that the ul's have a block of li's inside them not just single li's.
That is definately the first step I think.
CSS website design tutorials
- Rabid Dog
- Web Master


- Joined: May 21, 2004
- Posts: 3229
- Loc: South Africa
- Status: Offline
Okay so here is the output from the script as suggested
now let's assume for a second that we are not worried about download times (yeah right)
How would I wrap the sub items and sub item parents in seperate span tags?
Code: [ Select ]
<ul><li>Alcoholic Beverage Market</li>
<ul>
<li>Cans</li>
<ul></ul>
<li>Glass Bottles</li>
<ul></ul>
<li>HDPE Bottles</li>
<ul>
<li>Metallitone Cartons</li>
<ul></ul>
</ul>
<ul></ul>
<li>ROPP Wine and Spirit Closures</li>
<ul></ul>
<li>Crowns</li>
<ul></ul>
</ul>
</ul>
<ul>
<li>Cans</li>
<ul></ul>
<li>Glass Bottles</li>
<ul></ul>
<li>HDPE Bottles</li>
<ul>
<li>Metallitone Cartons</li>
<ul></ul>
</ul>
<ul></ul>
<li>ROPP Wine and Spirit Closures</li>
<ul></ul>
<li>Crowns</li>
<ul></ul>
</ul>
</ul>
- <ul><li>Alcoholic Beverage Market</li>
- <ul>
- <li>Cans</li>
- <ul></ul>
- <li>Glass Bottles</li>
- <ul></ul>
- <li>HDPE Bottles</li>
- <ul>
- <li>Metallitone Cartons</li>
- <ul></ul>
- </ul>
- <ul></ul>
- <li>ROPP Wine and Spirit Closures</li>
- <ul></ul>
- <li>Crowns</li>
- <ul></ul>
- </ul>
- </ul>
now let's assume for a second that we are not worried about download times (yeah right)
How would I wrap the sub items and sub item parents in seperate span tags?
Watch me grow
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
Ok here is the tree script. Ignore everything that is written in the tree. I have re-used an old html file that I was building a menu script with. It just so happend to have a heftily nested list in it:
http://www.caffeinefuelled.net/richard- ... /tree.html
The very top level ul has an ID but there are no other ID's used, each of the parent elements is a a tag of the form:
Thats all that is needed for it to work, but well formed html is important else it will go agh and die most likely. It also won't work in older versions of netscape but we can sort that out later.
Check out the source code so you know what html we aiming for, and I'll see what I have done wrong with your ASP.
--------------------------------------------------------------------------
Forgive this, it is me "thinking things through"
So the script work like this:
You have many records in the database.
Each record represents a item in the tree, whether that be an item a sub item, a sub sub item etc
The position in the tree is determined by the parent ID (which has actually give me an idea for something completely different so thankyou)
To get the needed code, it will need to run like this
But this is a problem, and won't work very well as we have to check if the element is a parent before we call the recursive function. So we can sort out a tags and suchlke.
so how about, running the entire script without putting in the a tags and then using a regular expression (which I am now quite fond oflol) to add these, where needed at the end.
Right. Does that sound like a plan? I'll get cracking on some pseudocode for that, to explain what I mean.
http://www.caffeinefuelled.net/richard- ... /tree.html
The very top level ul has an ID but there are no other ID's used, each of the parent elements is a a tag of the form:
Code: [ Select ]
<a href="#">parent element text</a>
Thats all that is needed for it to work, but well formed html is important else it will go agh and die most likely. It also won't work in older versions of netscape but we can sort that out later.
Check out the source code so you know what html we aiming for, and I'll see what I have done wrong with your ASP.
--------------------------------------------------------------------------
Forgive this, it is me "thinking things through"
So the script work like this:
You have many records in the database.
Each record represents a item in the tree, whether that be an item a sub item, a sub sub item etc
The position in the tree is determined by the parent ID (which has actually give me an idea for something completely different so thankyou)
To get the needed code, it will need to run like this
Code: [ Select ]
output "<ul id='treeview'>" //before we even start
get the top level elements (parentID='none' or whatever)
foreach of them
output "<li>"
if (parent){
output"<a href='#'>value</a>
Recursive function with this as parent
}else{
output "value"
}
output "</li>"
}
get the top level elements (parentID='none' or whatever)
foreach of them
output "<li>"
if (parent){
output"<a href='#'>value</a>
Recursive function with this as parent
}else{
output "value"
}
output "</li>"
}
- output "<ul id='treeview'>" //before we even start
- get the top level elements (parentID='none' or whatever)
- foreach of them
- output "<li>"
- if (parent){
- output"<a href='#'>value</a>
- Recursive function with this as parent
- }else{
- output "value"
- }
- output "</li>"
- }
But this is a problem, and won't work very well as we have to check if the element is a parent before we call the recursive function. So we can sort out a tags and suchlke.
so how about, running the entire script without putting in the a tags and then using a regular expression (which I am now quite fond oflol) to add these, where needed at the end.
Right. Does that sound like a plan? I'll get cracking on some pseudocode for that, to explain what I mean.
CSS website design tutorials
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
try
I'm sorry if any of the syntax is wrong, I have doe it as though it was normal VB, I don't know if there is any difference.
Can you try running that code to see a sample of the output.
BTW, I just noticed what you said about span tags. I'm not 100% sure what you mean or why you need them. Lol sometimes I get very confused easily
//---------------------------------------------------------------------
If that code is outputting like I hope it is, then you will need to do the following to the output string:
Replace the very first and only the first
with
then replace anything that looks like:
with
which will need to replace the .* with the exact same .* using a callback or something. I guess this could be done in the loop, but IMHO it will be simpler and neater to do it at the end
Code: [ Select ]
Public Sub getTree(parentID)
Dim rsData
Dim strSql
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
Set rsData = DBLink.Execute(strSql)
if rsData.recordcount>0 then 'we output nothing if there are no records returned
strOut = strOut & "<ul>" 'this will prevent the <ul></ul> from happening
While Not rsData.Eof
strOut = strOut & "<li>" & rsData(strDisplayRow)
call getTree(1,rsData(strIDRow),0)
strOut = strOut & "</li>" 'make sure that the sub section <ul> is nested inside this li
rsData.MoveNext
strOut = strOut & "</ul>"
Wend
end if
End Sub
Dim rsData
Dim strSql
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
Set rsData = DBLink.Execute(strSql)
if rsData.recordcount>0 then 'we output nothing if there are no records returned
strOut = strOut & "<ul>" 'this will prevent the <ul></ul> from happening
While Not rsData.Eof
strOut = strOut & "<li>" & rsData(strDisplayRow)
call getTree(1,rsData(strIDRow),0)
strOut = strOut & "</li>" 'make sure that the sub section <ul> is nested inside this li
rsData.MoveNext
strOut = strOut & "</ul>"
Wend
end if
End Sub
- Public Sub getTree(parentID)
- Dim rsData
- Dim strSql
- strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
- Set rsData = DBLink.Execute(strSql)
- if rsData.recordcount>0 then 'we output nothing if there are no records returned
- strOut = strOut & "<ul>" 'this will prevent the <ul></ul> from happening
- While Not rsData.Eof
- strOut = strOut & "<li>" & rsData(strDisplayRow)
- call getTree(1,rsData(strIDRow),0)
- strOut = strOut & "</li>" 'make sure that the sub section <ul> is nested inside this li
- rsData.MoveNext
- strOut = strOut & "</ul>"
- Wend
- end if
- End Sub
I'm sorry if any of the syntax is wrong, I have doe it as though it was normal VB, I don't know if there is any difference.
Can you try running that code to see a sample of the output.
BTW, I just noticed what you said about span tags. I'm not 100% sure what you mean or why you need them. Lol sometimes I get very confused easily
//---------------------------------------------------------------------
If that code is outputting like I hope it is, then you will need to do the following to the output string:
Replace the very first and only the first
Code: [ Select ]
<ul>
Code: [ Select ]
<ul id='treeview'>
then replace anything that looks like:
Code: [ Select ]
<li>.*<ul>
Code: [ Select ]
<li><a href='#'>.*</a><ul>
which will need to replace the .* with the exact same .* using a callback or something. I guess this could be done in the loop, but IMHO it will be simpler and neater to do it at the end
CSS website design tutorials
- Rabid Dog
- Web Master


- Joined: May 21, 2004
- Posts: 3229
- Loc: South Africa
- Status: Offline
Okay - legend. The code you gave me was slightly wrong but it had the right idea.
had to set rsData to a recordset object to get the recordCount and move the unorder list close tag outside the while loop.
Here is the revised sub
Works beautifully! Just need to look at it through different eyes. It is weird because in PHP i would have done that test in the first place, oh well.
Now for the next mission. How do we get it to see when it is a parent?
will try the checkParent function in the original posting
rtm you are a legend, thanks for the help, just this last one and we done - ps that js tree rocks![/b]
had to set rsData to a recordset object to get the recordCount and move the unorder list close tag outside the while loop.
Here is the revised sub
Code: [ Select ]
Public Sub getTree(parentID)
Dim rsData
Dim strSql
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
set rsData = Server.CreateObject("ADODB.Recordset")
rsData.CursorType = adOpenStatic
rsData.ActiveConnection = DBLink
rsData.Open strSql
if rsData.RecordCount>0 then 'we output nothing if there are no records returned
strOut = strOut & "<ul>"&vbCrLf 'this will prevent the <ul></ul> from happening
While Not rsData.Eof
strOut = strOut & "<li>" & rsData(strDisplayRow)
call getTree(rsData(strIDRow))
strOut = strOut & "</li>" & vbCrLf 'make sure that the sub section <ul> is nested inside this li
rsData.MoveNext
Wend
strOut = strOut & "</ul>" &vbCrLf
End if
End Sub
Dim rsData
Dim strSql
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
set rsData = Server.CreateObject("ADODB.Recordset")
rsData.CursorType = adOpenStatic
rsData.ActiveConnection = DBLink
rsData.Open strSql
if rsData.RecordCount>0 then 'we output nothing if there are no records returned
strOut = strOut & "<ul>"&vbCrLf 'this will prevent the <ul></ul> from happening
While Not rsData.Eof
strOut = strOut & "<li>" & rsData(strDisplayRow)
call getTree(rsData(strIDRow))
strOut = strOut & "</li>" & vbCrLf 'make sure that the sub section <ul> is nested inside this li
rsData.MoveNext
Wend
strOut = strOut & "</ul>" &vbCrLf
End if
End Sub
- Public Sub getTree(parentID)
- Dim rsData
- Dim strSql
- strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
- set rsData = Server.CreateObject("ADODB.Recordset")
- rsData.CursorType = adOpenStatic
- rsData.ActiveConnection = DBLink
- rsData.Open strSql
- if rsData.RecordCount>0 then 'we output nothing if there are no records returned
- strOut = strOut & "<ul>"&vbCrLf 'this will prevent the <ul></ul> from happening
- While Not rsData.Eof
- strOut = strOut & "<li>" & rsData(strDisplayRow)
- call getTree(rsData(strIDRow))
- strOut = strOut & "</li>" & vbCrLf 'make sure that the sub section <ul> is nested inside this li
- rsData.MoveNext
- Wend
- strOut = strOut & "</ul>" &vbCrLf
- End if
- End Sub
Works beautifully! Just need to look at it through different eyes. It is weird because in PHP i would have done that test in the first place, oh well.
Now for the next mission. How do we get it to see when it is a parent?
will try the checkParent function in the original posting
rtm you are a legend, thanks for the help, just this last one and we done - ps that js tree rocks![/b]
Watch me grow
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
If you want the js tree <i>should</i> work in IE5,5.5,6 NSN7, Firefox, Moz, Opera 7.
To get it to work in older versions of netscape & Moz I <i>think</i> you need to do some browser siffing and remove the .style wherever it appears for netscape.
//edit - I've just updated the tree so that if the user has no js then it will remain open, and if the user does have js, it will be collapsed from the start, rather than waiting for the page to load first.
Well if you run the getTree function with a parameter that is not a parent, then it will return nothing.
If you check the edit on the last post, that should get you on the right track for altering the outputted string to give the a tags where neccesary.
The checkParent might then become redundant if you do it that way, although I can't be sure.
To get it to work in older versions of netscape & Moz I <i>think</i> you need to do some browser siffing and remove the .style wherever it appears for netscape.
//edit - I've just updated the tree so that if the user has no js then it will remain open, and if the user does have js, it will be collapsed from the start, rather than waiting for the page to load first.
Well if you run the getTree function with a parameter that is not a parent, then it will return nothing.
If you check the edit on the last post, that should get you on the right track for altering the outputted string to give the a tags where neccesary.
The checkParent might then become redundant if you do it that way, although I can't be sure.
CSS website design tutorials
- Rabid Dog
- Web Master


- Joined: May 21, 2004
- Posts: 3229
- Loc: South Africa
- Status: Offline
YEAH Got it sorted!
Okay so here is the code for the revised class
Just finished now and I read your edit rtm and well we where kinda on the same wave length because I made the changes before coming back.
Well the class is working but we have a problem Mr Perfectionist. lol
Considering the fact that this query will generate over 40 kb of data, we are going to have a heck of a long menu system jumping around.
The problem I pose to you is how do we make this tree contract to display only the relative sub links for the master link or sub master link selected?
PS feel free to use the above class if you find a need for it, might need a bit of editing though in terms of display classes etc.
PS thanks for the help again
Okay so here is the code for the revised class
Code: [ Select ]
<%
Class recursion
Private DBLink ' DB Reference
Private fRun
Public strMasterRow ' row Containg pk - to be removed
Public strDisplayRow ' Row name to be displayed
Public strIDRow ' row containing PK
Public strTable ' table name
Public strParentRow ' Parent row name
Public strParentClass ' Display Class
Public strChildClass ' Display Class
Public strOut 'String to be displayed
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
Set DBLink = openDB() ' External function
fRun = " id='treeview'"
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Terminate()
closeDatabase(DBLink) ' external function
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub getTree(parentID)
Dim rsData
Dim strSql
Dim bool
Dim closeA : closeA = 0
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
set rsData = Server.CreateObject("ADODB.Recordset")
rsData.CursorType = adOpenStatic
rsData.ActiveConnection = DBLink
rsData.Open strSql
if rsData.RecordCount>0 then 'we output nothing if there are no records returned
strOut = strOut & "<ul"&fRun&">"&vbCrLf 'this will prevent the <ul></ul> from happening
fRun = ""
While Not rsData.Eof
bool = checkParent(rsData(strIDRow))
strOut = strOut & "<li>"
if bool = True then
strOut = strOut & "<a href='#'>"
closeA = 1
End If
strOut = strOut & rsData(strDisplayRow)
if closeA = 1 then
strOut = strOut & "</a>"
closeA = 0
End if
call getTree(rsData(strIDRow))
strOut = strOut & "</li>" & vbCrLf 'make sure that the sub section <ul> is nested inside this li
rsData.MoveNext
Wend
strOut = strOut & "</ul>" &vbCrLf
End if
'HOUSKEEPING
rsData.Close
Set rsData = Nothing
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function checkParent(parentID)
Dim rsData, strSql
strSql = "SELECT " &strParentRow& " FROM " &strTable& " WHERE " &strParentRow& " = '" &parentID& "'"
Set rsData = DBLink.Execute(strSql)
If Not rsData.Eof then
checkParent = True
Else
checkParent = False
End If
rsData.Close
Set rsData = Nothing
End Function
End Class
%>
Class recursion
Private DBLink ' DB Reference
Private fRun
Public strMasterRow ' row Containg pk - to be removed
Public strDisplayRow ' Row name to be displayed
Public strIDRow ' row containing PK
Public strTable ' table name
Public strParentRow ' Parent row name
Public strParentClass ' Display Class
Public strChildClass ' Display Class
Public strOut 'String to be displayed
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
Set DBLink = openDB() ' External function
fRun = " id='treeview'"
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Terminate()
closeDatabase(DBLink) ' external function
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub getTree(parentID)
Dim rsData
Dim strSql
Dim bool
Dim closeA : closeA = 0
strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
set rsData = Server.CreateObject("ADODB.Recordset")
rsData.CursorType = adOpenStatic
rsData.ActiveConnection = DBLink
rsData.Open strSql
if rsData.RecordCount>0 then 'we output nothing if there are no records returned
strOut = strOut & "<ul"&fRun&">"&vbCrLf 'this will prevent the <ul></ul> from happening
fRun = ""
While Not rsData.Eof
bool = checkParent(rsData(strIDRow))
strOut = strOut & "<li>"
if bool = True then
strOut = strOut & "<a href='#'>"
closeA = 1
End If
strOut = strOut & rsData(strDisplayRow)
if closeA = 1 then
strOut = strOut & "</a>"
closeA = 0
End if
call getTree(rsData(strIDRow))
strOut = strOut & "</li>" & vbCrLf 'make sure that the sub section <ul> is nested inside this li
rsData.MoveNext
Wend
strOut = strOut & "</ul>" &vbCrLf
End if
'HOUSKEEPING
rsData.Close
Set rsData = Nothing
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function checkParent(parentID)
Dim rsData, strSql
strSql = "SELECT " &strParentRow& " FROM " &strTable& " WHERE " &strParentRow& " = '" &parentID& "'"
Set rsData = DBLink.Execute(strSql)
If Not rsData.Eof then
checkParent = True
Else
checkParent = False
End If
rsData.Close
Set rsData = Nothing
End Function
End Class
%>
- <%
- Class recursion
- Private DBLink ' DB Reference
- Private fRun
- Public strMasterRow ' row Containg pk - to be removed
- Public strDisplayRow ' Row name to be displayed
- Public strIDRow ' row containing PK
- Public strTable ' table name
- Public strParentRow ' Parent row name
- Public strParentClass ' Display Class
- Public strChildClass ' Display Class
- Public strOut 'String to be displayed
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub Class_Initialize()
- Set DBLink = openDB() ' External function
- fRun = " id='treeview'"
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub Class_Terminate()
- closeDatabase(DBLink) ' external function
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Public Sub getTree(parentID)
- Dim rsData
- Dim strSql
- Dim bool
- Dim closeA : closeA = 0
- strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
- set rsData = Server.CreateObject("ADODB.Recordset")
- rsData.CursorType = adOpenStatic
- rsData.ActiveConnection = DBLink
- rsData.Open strSql
- if rsData.RecordCount>0 then 'we output nothing if there are no records returned
- strOut = strOut & "<ul"&fRun&">"&vbCrLf 'this will prevent the <ul></ul> from happening
- fRun = ""
- While Not rsData.Eof
- bool = checkParent(rsData(strIDRow))
- strOut = strOut & "<li>"
- if bool = True then
- strOut = strOut & "<a href='#'>"
- closeA = 1
- End If
- strOut = strOut & rsData(strDisplayRow)
- if closeA = 1 then
- strOut = strOut & "</a>"
- closeA = 0
- End if
- call getTree(rsData(strIDRow))
- strOut = strOut & "</li>" & vbCrLf 'make sure that the sub section <ul> is nested inside this li
- rsData.MoveNext
- Wend
- strOut = strOut & "</ul>" &vbCrLf
- End if
- 'HOUSKEEPING
- rsData.Close
- Set rsData = Nothing
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Function checkParent(parentID)
- Dim rsData, strSql
- strSql = "SELECT " &strParentRow& " FROM " &strTable& " WHERE " &strParentRow& " = '" &parentID& "'"
- Set rsData = DBLink.Execute(strSql)
- If Not rsData.Eof then
- checkParent = True
- Else
- checkParent = False
- End If
- rsData.Close
- Set rsData = Nothing
- End Function
- End Class
- %>
Just finished now and I read your edit rtm and well we where kinda on the same wave length because I made the changes before coming back.
Well the class is working but we have a problem Mr Perfectionist. lol
Considering the fact that this query will generate over 40 kb of data, we are going to have a heck of a long menu system jumping around.
The problem I pose to you is how do we make this tree contract to display only the relative sub links for the master link or sub master link selected?
PS feel free to use the above class if you find a need for it, might need a bit of editing though in terms of display classes etc.
PS thanks for the help again
Watch me grow
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
Quote:
The problem I pose to you is how do we make this tree contract to display only the relative sub links for the master link or sub master link selected?
Click on the other links that are open first?
ahhhhhhh damn you. Yeah this involves a whole load of looping to be done, and I was hoping you wouldn't ask for that. Personally I would rather not alter the html. Simply for the reason that I only give id's and classes to "container" elements unless I really have to. It keeps the html clean (and also makes people wonder how the hell it works!).
I'm gonna htink of an efficient way of doing it before I jump into the code. I'll get back to you in a bit.
CSS website design tutorials
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
- Rabid Dog
- Web Master


- Joined: May 21, 2004
- Posts: 3229
- Loc: South Africa
- Status: Offline
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
Rabid Dog wrote:
If yo u were in SA I would send you a bottle of Jacks
Thanks rtm, you get my vote
Thanks rtm, you get my vote
If I was then I'd save you the trouble, I don't drink!
It's ok, I seem to see you here all the time helping other people, including me, so I'm more than happy to help you back.
Any chance I can see a sample of the script in operation?
CSS website design tutorials
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
June 10th, 2004, 8:03 am
1, 2
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 18 posts
- Users browsing this forum: No registered users and 122 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
