Solved

ColdFusion, CFLoop, indented list from query

Posted on 2008-06-25
6
517 Views
Last Modified: 2013-12-24
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?
0
Comment
Question by:fbouzek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 2

Expert Comment

by:dbanttari
ID: 21868750
Treat each value as a "~"-delimited list, and use CF's handy list functions.

query: select pageHierarchy from pages order by id

code:
<cfoutput query="q">
  #repeatString("&nbsp;", listLen(pageHierarchy,"~")-1)##listLast(pageHierarchy,"~")#
</cfoutput>

Open in new window

0
 
LVL 4

Expert Comment

by:msfletch
ID: 21868930
Brilliant solution by dbanttari. Just add "<br />" to the end of the variable line.
0
 

Author Comment

by:fbouzek
ID: 21868972
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
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:fbouzek
ID: 21868989
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
0
 
LVL 2

Accepted Solution

by:
dbanttari earned 125 total points
ID: 21869058
The repeatString part should be doing the indentation.  And yes, i forgot to put a <br /> at the end of the line.

Reposting, using <p>...</p>
<cfoutput query="q">
  <p>#repeatString("&nbsp;", listLen(pageHierarchy,"~")-1)##listLast(pageHierarchy,"~")#</p>
</cfoutput>

Open in new window

0
 
LVL 4

Expert Comment

by:msfletch
ID: 21869077
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("&nbsp;&nbsp;&nbsp;", listLen(pageHierarchy,"~")-1)##listLast(pageHierarchy,"~")#<br>
</cfoutput>
 
</body>
</html>

Open in new window

0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question