ASP recursion issue

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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

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

%>
  1. <%
  2. Class recursion
  3. Private DBLink                                ' DB Reference
  4. Public strMasterRow                    ' row Containg pk - to be removed
  5. Public strDisplayRow                    ' Row name to be displayed
  6. Public strIDRow                            ' row containing PK
  7. Public strTable                            ' table name
  8. Public strParentRow                    '    Parent row name
  9. Public strParentClass                ' Display Class
  10. Public strChildClass                    ' Display Class
  11. Public strOut                                 'String to be displayed
  12. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  13. Private Sub Class_Initialize()
  14.     Set DBLink        = openDB()            ' External function
  15. End Sub
  16. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  17. Private Sub Class_Terminate()
  18.     closeDatabase(DBLink)                    ' external function
  19. End Sub
  20. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  21. Public Sub getTree(parentID)
  22.         Dim rsData
  23.      Dim strSql
  24.      
  25.      strSql     = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
  26.      Set rsData   = DBLink.Execute(strSql)
  27.      While Not rsData.Eof
  28.          strOut        = strOut & "<ul>"
  29.          strOut        = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
  30.          call getTree(1,rsData(strIDRow),0)
  31.          strOut        = strOut & "</ul>"
  32.          rsData.MoveNext
  33.      Wend
  34. End Sub
  35.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  36. Private Function checkParent(parentID)
  37.     Dim rsData, strSql
  38.     strSql                            = "SELECT " &strParentRow& " FROM " &strTable& " WHERE " &strParentRow& " = '" &parentID& "'"
  39.     Set rsData                    = DBLink.Execute(strSql)
  40.     If Not rsData.Eof then
  41.         checkParent                = True
  42.     Else
  43.         checkParent                = False
  44.     End If
  45.     rsData.Close
  46.     Set rsData                    = Nothing
  47. End Function
  48. End Class
  49. %>


Thanks guys
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

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?

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 :wink:

Can you clarify the question?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

If you could supply me with a quality tree script I would appreciate that.

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>
  1. item one
  2. <ul id="item1"><li>sub item one</li></ul>
  3. <ul id="item1"><li>sub item two</li>
  4.     <ul id="subitem2">
  5.         <li>sub sub item one</li>
  6.         <li>sub sub item two</li>
  7.      </ul>
  8. </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 :banghead:
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Ok I just looked closer at the ASP and it looks to me like you are getting something like this output i the html
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>
  1. <ul><li>Item Text here</li></ul>
  2. <ul><li>Item Text here</li></ul>
  3. <ul><li>Item Text here</li></ul>
  4. <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>
  1. <ul>
  2.   <li>Item Text here</li>
  3.   <li>Item Text here</li>
  4.   <li>Item Text here</li>
  5.   <li>Item Text here</li>
  6. </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>
  1. <ul>
  2.   <li>Item Text here</li>
  3.   <li>Parent Item Text here
  4.     <ul>
  5.       <li>Item Text here</li>
  6.       <li>Item Text here</li>
  7.       <li>Item Text here</li>
  8.       <li>Item Text here</li>
  9.     </ul>
  10.   </li>
  11.   <li>Item Text here</li>
  12.   <li>Item Text here</li>
  13. </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
  1.    strSql     = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
  2.    Set rsData   = DBLink.Execute(strSql)
  3.    While Not rsData.Eof
  4.     strOut   = strOut & "<ul>"
  5.     strOut   = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
  6.     call getTree(1,rsData(strIDRow),0)
  7.     strOut   = strOut & "</ul>"
  8.     rsData.MoveNext
  9.    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>"
  1.    strSql     = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
  2.    Set rsData   = DBLink.Execute(strSql)
  3.    strOut   = strOut & "<ul>"
  4.    While Not rsData.Eof
  5.     strOut   = strOut & "<li>" & rsData(strDisplayRow) & "</li>"
  6.     call getTree(1,rsData(strIDRow),0)
  7.     rsData.MoveNext
  8.    Wend    
  9.    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.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Okay so here is the output from the script as suggested

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>
  1. <ul><li>Alcoholic Beverage Market</li>
  2.     <ul>
  3.         <li>Cans</li>
  4.     <ul></ul>
  5.         <li>Glass Bottles</li>
  6.     <ul></ul>
  7.         <li>HDPE Bottles</li>
  8.         <ul>
  9.             <li>Metallitone Cartons</li>
  10.         <ul></ul>
  11.         </ul>
  12.     <ul></ul>
  13.         <li>ROPP Wine and Spirit Closures</li>
  14.     <ul></ul>
  15.         <li>Crowns</li>
  16.     <ul></ul>
  17.     </ul>
  18. </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?
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Is that what comes out when you make the edit I suggested?

:oops: I may very well have done something wrong. I'll just finish this tree script and then I'll get back to you.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

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:
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>"
}
  1. output "<ul id='treeview'>"  //before we even start
  2. get the top level elements (parentID='none' or whatever)
  3. foreach of them
  4.   output "<li>"
  5.   if (parent){
  6.     output"<a href='#'>value</a>
  7.     Recursive function with this as parent
  8.   }else{
  9.     output "value"
  10.   }
  11.   output "</li>"
  12. }


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.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

try
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
  1. Public Sub getTree(parentID)
  2.     Dim rsData
  3.     Dim strSql
  4.     strSql     = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
  5.     Set rsData   = DBLink.Execute(strSql)
  6.     if rsData.recordcount>0 then                'we output nothing if there are no records returned
  7.         strOut   = strOut & "<ul>"            'this will prevent the <ul></ul> from happening
  8.         While Not rsData.Eof
  9.             strOut   = strOut & "<li>" & rsData(strDisplayRow)
  10.             call getTree(1,rsData(strIDRow),0)
  11.             strOut   = strOut & "</li>"        'make sure that the sub section <ul> is nested inside this li
  12.             rsData.MoveNext
  13.             strOut   = strOut & "</ul>"
  14.         Wend
  15.     end if
  16. 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 :lol:


//---------------------------------------------------------------------
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>
with
Code: [ Select ]
<ul id='treeview'>


then replace anything that looks like:
Code: [ Select ]
<li>.*<ul>
with
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
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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

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
  1. Public Sub getTree(parentID)
  2.    Dim rsData
  3.    Dim strSql
  4.   
  5.    strSql                         = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
  6.    set rsData                                 = Server.CreateObject("ADODB.Recordset")
  7.    rsData.CursorType                = adOpenStatic
  8.    rsData.ActiveConnection    = DBLink
  9.    rsData.Open strSql
  10.    if rsData.RecordCount>0 then                      'we output nothing if there are no records returned
  11.    strOut   = strOut & "<ul>"&vbCrLf     'this will prevent the <ul></ul> from happening
  12.    While Not rsData.Eof
  13.      strOut   = strOut & "<li>" & rsData(strDisplayRow)
  14.      call getTree(rsData(strIDRow))
  15.      strOut   = strOut & "</li>" & vbCrLf   'make sure that the sub section <ul> is nested inside this li
  16.      rsData.MoveNext
  17.    Wend
  18.    strOut   = strOut & "</ul>" &vbCrLf
  19.    End if
  20. 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]
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

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.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

YEAH Got it sorted!

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

%>
  1. <%
  2. Class recursion
  3. Private DBLink ' DB Reference
  4. Private fRun
  5.  
  6. Public strMasterRow ' row Containg pk - to be removed
  7. Public strDisplayRow ' Row name to be displayed
  8. Public strIDRow     ' row containing PK
  9. Public strTable      ' table name
  10. Public strParentRow '  Parent row name
  11. Public strParentClass ' Display Class
  12. Public strChildClass  ' Display Class
  13.  
  14. Public strOut     'String to be displayed
  15. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  16. Private Sub Class_Initialize()
  17.   Set DBLink   = openDB()  ' External function
  18.    fRun    = " id='treeview'"
  19. End Sub
  20. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  21. Private Sub Class_Terminate()
  22.   closeDatabase(DBLink)  ' external function
  23. End Sub
  24. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  25. Public Sub getTree(parentID)
  26.    Dim rsData
  27.    Dim strSql
  28.    Dim bool
  29.    Dim closeA        : closeA = 0
  30.   
  31.   
  32.    strSql = "SELECT * FROM " &strTable&" WHERE " &strParentRow&" = '" & ParentID & "'"
  33.    set rsData = Server.CreateObject("ADODB.Recordset")
  34.    rsData.CursorType = adOpenStatic
  35.    rsData.ActiveConnection    = DBLink
  36.    rsData.Open strSql
  37.    if rsData.RecordCount>0 then                      'we output nothing if there are no records returned
  38.    strOut = strOut & "<ul"&fRun&">"&vbCrLf     'this will prevent the <ul></ul> from happening
  39.    fRun    = ""
  40.    While Not rsData.Eof
  41.      bool = checkParent(rsData(strIDRow))
  42.      strOut = strOut & "<li>"
  43.      if bool = True then
  44.          strOut = strOut & "<a href='#'>"
  45.          closeA = 1
  46.      End If
  47.      strOut = strOut & rsData(strDisplayRow)
  48.      if closeA = 1 then
  49.          strOut = strOut & "</a>"
  50.          closeA = 0
  51.      End if
  52.      call getTree(rsData(strIDRow))
  53.      strOut = strOut & "</li>" & vbCrLf   'make sure that the sub section <ul> is nested inside this li
  54.      rsData.MoveNext
  55.    Wend
  56.    strOut = strOut & "</ul>" &vbCrLf
  57.    End if
  58.    'HOUSKEEPING
  59.    rsData.Close
  60.    Set rsData = Nothing
  61. End Sub
  62.   '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  63. Private Function checkParent(parentID)
  64.   Dim rsData, strSql
  65.   strSql           = "SELECT " &strParentRow& " FROM " &strTable& " WHERE " &strParentRow& " = '" &parentID& "'"
  66.   Set rsData        = DBLink.Execute(strSql)
  67.   If Not rsData.Eof then
  68.     checkParent = True
  69.   Else
  70.     checkParent = False
  71.   End If
  72.   rsData.Close
  73.   Set rsData = Nothing
  74. End Function
  75. End Class
  76. %>


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
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

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.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Sometimes glitches and requires being clicked twice to open. Not sure why. Same link:

http://www.caffeinefuelled.net/richard- ... /tree.html

//edit - fixed :D

//edit, I'm not too happy with the size of the JS, will try to slim it down a bit :lol:
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Legend man - okay here you go :iconthumbright: respect!

Works like a charm!

If yo u were in SA I would send you a bottle of Jacks

Thanks rtm, you get my vote
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Rabid Dog wrote:
If yo u were in SA I would send you a bottle of Jacks

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?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Um one last favor?

need the bullets to change from plus to minus on the page

last thing I promise then I will send you the url
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Ok, to get it to work the same in both IE and Firefox, I had to add a white border to the left ahnd side. No idea why but I did. It's in the style tag and so you will have to change the CSS property to match the background of the page.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Thanks again rtm, working but there is a bug which I will sort out tomorrow - on my way home now - Cheers

Post Information

  • Total Posts in this topic: 18 posts
  • Users browsing this forum: No registered users and 61 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.