Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ColdFusion, CFLoop, indented list from query

Posted on 2008-06-25
6
Medium Priority
?
540 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
  • 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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 

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 500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
Suggested Courses

824 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