Solved

ColdFusion, CFLoop, indented list from query

Posted on 2008-06-25
6
489 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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 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…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

757 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

19 Experts available now in Live!

Get 1:1 Help Now