fbouzek
asked on
ColdFusion, CFLoop, indented list from query
Trying to make an indented list from a query, There is a page Hierarchy column in the database
id pageHierarchy
1 1
2 1~2
3 3
4 4
5 4~5
6 4~5~6
7 4~5~6~7
8 8
Indented list:
1
2
3
4
5
6
7
8
What would my query and output look like?
id pageHierarchy
1 1
2 1~2
3 3
4 4
5 4~5
6 4~5~6
7 4~5~6~7
8 8
Indented list:
1
2
3
4
5
6
7
8
What would my query and output look like?
Brilliant solution by dbanttari. Just add "<br />" to the end of the variable line.
ASKER
I was working with this, but couldn't figure out where to the list tags for I can get the list, just cannot indent them
ASKER
Well, that was clear as mud. let me try again.
I was working with this, but couldn't figure out where or how to put the list tags so it would indent the list for each level
I was working with this, but couldn't figure out where or how to put the list tags so it would indent the list for each level
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Code indents the list with the output of each row being caused by the <Cfoutput> tag with the QUERY value. See attached code using dbanttari's solution with a test query created.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--- get data from table --->
<!--- <cfquery datasource="datasource" name="getHierarchy">
SELECT id, pageHierarchy
FROM hTable
ORDER BY Id
</cfquery> --->
<!--- test query --->
<cfset getHierarchy= querynew("")>
<cfset queryaddcolumn (getHierarchy, "id", "CF_SQL_integer", ListToArray("1,2,3,4,5,6,7,8"))>
<cfset queryaddcolumn (getHierarchy, "pageHierarchy", "cf_sql_varchar", ListToArray("1,1~2,3,4,4~5,4~5~6,4~5~6~7,8"))>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<cfoutput query="getHierarchy">
#repeatString(" ", listLen(pageHierarchy,"~")-1)##listLast(pageHierarchy,"~")#<br>
</cfoutput>
</body>
</html>
query: select pageHierarchy from pages order by id
code:
Open in new window