Got it sussed -

Function GetSubPages (parentID)

Dim oRS

sSQL = "SELECT * FROM tbl_Content_Page WHERE p_parentID = " & parentID

Set oRS = oData.ExecSQL(sSQL, 4, "", "", "")

If Not oRS.EOF Then

Do While Not oRS.EOF
        Response.Write "p_id: " & oRS(0) & ", p_title: " & oRS(1) & "<br>"
        Call GetSubPages(oRS(0))
        oRS.MoveNext
Loop

End If
        
End Function

I was getting a BOF or EOF error until I moved the oRS declaration inside
the function. Works fine now. You call the function like GetSubPages(1) and
it works its way down through the table until there are no more records,
then moves back up and works down the next branch of the tree. Handy piece
of code if anyone is looking for something like this. Feel free to use it.

Cheers,

Alastair

-----Original Message-----
From: Alastair Moore [mailto:[EMAIL PROTECTED] 
Sent: 22 June 2004 10:24
To: '[EMAIL PROTECTED]'
Subject: RE: [AspClassicAnyQuestionIsOk] slightly OT: selecting "child rec
ords"

Hello all again,

I've decided against doing it in SQL - I can't work out a query! - so am
doing it in ASP. This is where I'm up to so far -

Function GetSubPages (parentID)

sSQL = "SELECT * FROM tbl_Content_Page WHERE p_parentID = " & parentID
Set oRS = oData.ExecSQL(sSQL, 4, "", "", "")

Do While Not oRS.EOF
Response.Write "id: "&oRS(0)&", title: "&oRS(1)&", parent: "&oRS(3)&"<br>"
Call GetSubPages(oRS(0))
oRS.MoveNext
Loop
                
End Function

I kind of understand what I'm trying to do.. basically keep calling the same
function until there are no more records.

Any thoughts?

Cheers,

Alastair

-----Original Message-----
From: Alastair Moore [mailto:[EMAIL PROTECTED] 
Sent: 22 June 2004 09:27
To: '[EMAIL PROTECTED]'
Subject: [AspClassicAnyQuestionIsOk] slightly OT: selecting "child records"


Hi all,

I've got a database which contains a table with several records.. there's a
sort of parent/child hierarchy going on.. I want to select a specific parent
record and then create a query that'll list all it's child items.. at the
moment I can only select the next level down, not all levels of child
records.. any ideas?

Table definition is like the following -

p_id            - autonumber
p_parentid      - number
p_title - text
p_active        - yes/no

A sample selection of records could be -

1       0       Home            Yes
2       1       About Us        Yes
3       1       Contact Us      Yes
4       2       Company Yes
5       2       Staff           Yes
6       2       History Yes
7       3       Offices Yes
8       3       Location        Yes
9       4       Blah            Yes
10      4       Blah 2  Yes

So if I was to do a select on 2 - about us, I would expect to get the
following results -

4       2       Company Yes
5       2       Staff           Yes
6       2       History Yes
9       4       Blah            Yes
10      4       Blah 2  Yes

Any help with this would be much, much appreciated!

Cheers,

Alastair

 



 
Yahoo! Groups Links



 


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/AspClassicAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
     [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 

Reply via email to