vouzamo
10-02-2007, 11:01 AM
I am looking to store html tag information in a database to dynamically generate html code from. I have a database as shown below:
database tbl.CMS_pagemap:
id name parent has_child
0 html yes
1 head 0 yes
2 script 1
3 style 1
4 body 0
5 foot 0
An asp page should run a function: writeTags() to pull in any tag with parent set to "" (in this example it should pull in 'html'). Then the code should check if has_child is set to "yes". If so it should call the function writeTags() from within itself using the new parent id set to the id of the current record (in this example it should be 0). This should continue until there are no more children.
The problem I am having is that the code writes 2 copies of the closing tag (shown below) if it is the last child of a level
closing tag:
</<%= name %>><br>
Is there an if statement that will check if this is the last record in a movenext() sequence so I could only write this line when appropriate?
Any alternative methods for achieving my objective will be welcomed. ASP source code and page grab can be found below along with a link to the live page:
source code (recursive.asp):
<%
function writeTag(id)
set conn = server.createobject("adodb.connection")
connection = "driver={MySql ODBC 3.51 Driver};server=[removed];uid=[removed];pwd=[removed];database=[removed]"
conn.open (connection)
set result = server.createobject("adodb.recordset")
sql = "SELECT * FROM CMS_pagemap WHERE parent = '" & id & "' ORDER BY id"
set result = conn.execute(sql)
while not result.EOF
name = result("name")
parent = result("parent")
id = result("id")
has_child = result("has_child")
%>
<<%= name %>><br>
<%
if has_child = "yes" then
writeTag(id)
else
%>
</<%= name %>><br>
<%
end if
result.movenext()
wend
%>
</<%= name %>><br>
<%
end function
writeTag("")
%>
page grab:
<html>
<head>
<script>
</script>
<style>
</style>
</style>
<body>
</body>
<foot>
</foot>
</foot>
</html>
live page:
http://www.vouzamo.co.uk/cms/admin/recursive.asp
database tbl.CMS_pagemap:
id name parent has_child
0 html yes
1 head 0 yes
2 script 1
3 style 1
4 body 0
5 foot 0
An asp page should run a function: writeTags() to pull in any tag with parent set to "" (in this example it should pull in 'html'). Then the code should check if has_child is set to "yes". If so it should call the function writeTags() from within itself using the new parent id set to the id of the current record (in this example it should be 0). This should continue until there are no more children.
The problem I am having is that the code writes 2 copies of the closing tag (shown below) if it is the last child of a level
closing tag:
</<%= name %>><br>
Is there an if statement that will check if this is the last record in a movenext() sequence so I could only write this line when appropriate?
Any alternative methods for achieving my objective will be welcomed. ASP source code and page grab can be found below along with a link to the live page:
source code (recursive.asp):
<%
function writeTag(id)
set conn = server.createobject("adodb.connection")
connection = "driver={MySql ODBC 3.51 Driver};server=[removed];uid=[removed];pwd=[removed];database=[removed]"
conn.open (connection)
set result = server.createobject("adodb.recordset")
sql = "SELECT * FROM CMS_pagemap WHERE parent = '" & id & "' ORDER BY id"
set result = conn.execute(sql)
while not result.EOF
name = result("name")
parent = result("parent")
id = result("id")
has_child = result("has_child")
%>
<<%= name %>><br>
<%
if has_child = "yes" then
writeTag(id)
else
%>
</<%= name %>><br>
<%
end if
result.movenext()
wend
%>
</<%= name %>><br>
<%
end function
writeTag("")
%>
page grab:
<html>
<head>
<script>
</script>
<style>
</style>
</style>
<body>
</body>
<foot>
</foot>
</foot>
</html>
live page:
http://www.vouzamo.co.uk/cms/admin/recursive.asp