musicradiolive Posted April 15, 2008 Share Posted April 15, 2008 Hi All,I need some help with Parent & Child data.Basically, all my pages are stored in a database. The website contains sections and then in each section is the pages for that part of the site.The database is laid out like this:ID - The page ID NumberPName - The Page NamePCon - The Page ContentPType - Page Type (EITHER PARENT/CHILD)PParent - Parent of the page (If child).If the page is a parent then i just set the PParent to 0000.I want to display all the pages within the site as a table, in the layout of: <table width="100%" border="0"><tr><td>ID</td><td>Name</td></tr>---IF THE PAGE IS A PARENT IT THEN DISPLAYS:<tr><td><% =rs("ID") %></td><td><% =rs("PName") %></td></tr>---THEN IT MOVES ON TO DISPLAY THE NEXT PARENT.---HOWEVER, IF THERE IS A CHILD THAT BELONG TO THE PARENT (Found by ID, so if PParent = The ID of the parent pageit belongs to it)So then it will show:The parent as above then:<table width="100%><tr><td> </td><td><% = rs("id") %></td><td><% =rs("PName") %></td></tr></table>---THEN IT WILL CARRY ON. Thanks in advance for any help on this.Jon Link to comment Share on other sites More sharing options...
justsomeguy Posted April 15, 2008 Share Posted April 15, 2008 You need to use a recursive function that will print a page and whatever children are under it, and children of those children, etc. Hopefully you're using Javascript for this. function print_page(id){ var rs = Server.CreateObject("ADODB.RecordSet"); rs.ActiveConnection = your_dbcon_string; rs.Open("SELECT * FROM table WHERE id=" + id); if (rs.fields.item("PParent").value == 0) { Response.Write("<tr>"); Response.Write("<td>" + rs.fields.item("ID").value + "</td>"); Response.Write("<td>" + rs.fields.item("PName").value + "</td>"); Response.Write("</tr>"); } else { Response.Write("<table width=\"100%\">"); Response.Write("<tr>"); Response.Write("<td> </td>"); Response.Write("<td>" + rs.fields.item("ID").value + "</td>"); Response.Write("<td>" + rs.fields.item("PName").value + "</td>"); Response.Write("</tr>"); Response.Write("</table>"); } rs.Close(); rs.Open("SELECT ID FROM table WHERE PParent=" + id); while (!rs.eof) { print_page(rs.fields.item("ID").value); rs.MoveNext(); } rs.Close();} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.