Solved

ColdFusion, CFLoop, indented list from query

Posted on 2008-06-25
6
492 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
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…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

912 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now