Solved

ColdFusion, CFLoop, indented list from query

Posted on 2008-06-25
6
508 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
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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 Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

820 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