[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

put results of a query into a list

Posted on 2003-10-21
15
Medium Priority
?
164 Views
Last Modified: 2013-12-24
with the follwing code:

<cfquery datasource="wrightdb" name="getButtons">
      SELECT ButtonName as names FROM NavLeftButtons
</cfquery>
<cfoutput query="getButtons">#getButtons.names#</cfoutput>

The page disply looks like:

button1button2button3button4

I want to be able to load these into a comma delimited list so I can get at the individual items.  Is there a way to do this more directly out of the query?

Just so you know, I am doing this in order to dynamically populate a navigation button bar with buttons appropriate for the specific user.
0
Comment
Question by:David Williamson
  • 8
  • 5
  • 2
15 Comments
 
LVL 2

Author Comment

by:David Williamson
ID: 9594950
Although I still want to know that answer to that question above, I think I may have answered my own question regarding autopopulating nav buttons.  Here is the code:

<body onLoad="MM_preloadImages('Images/arch_flare.jpg')">
<table cellpadding="0" cellspacing="0" border="0" width="185">
      <tr>
      <td><cfoutput>
      <cfloop query="getButtons">
      <cfparam name="loop_no" default="1">
      <cfset loop_no=loop_no + 1>
      <a href="Index.cfm" onMouseOver="MM_swapImage('Image#loop_no#','','Images/arch_flare.jpg',1)" onMouseOut="MM_swapImgRestore()">
       <img src="Images/#getButtons.ButtonName#.jpg" name="Image#loop_no#" width="185" height="25" border="0" id="Image#loop_no#"></a><br>
      </cfloop></cfoutput>
      </td>
      </tr>
</table>
</body>

So I guess my new/additional question would be, how could I write this code better?
0
 
LVL 2

Accepted Solution

by:
jonnygo55 earned 400 total points
ID: 9594984
#valueList(getButtons.names)# or in this case #quotedValueList(getButtons.names)#
0
 
LVL 2

Author Comment

by:David Williamson
ID: 9594996
cool.  I'll have to look that one up; I'm not familiar with it.  So it just creates a list from the variable?

What do you think about my second code post?  A better way to accomplish the same thing?
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
LVL 2

Expert Comment

by:jonnygo55
ID: 9595052
that'll work...
I would use <cfoutput query="getButtons"> instead of <cfloop... as a matter of practice
0
 
LVL 2

Author Comment

by:David Williamson
ID: 9595088
I guess cfoutput does the same exact thing as cfloop in this case, doesn't it?  

Another question: isn't there a reserved variable like #getButtons.CurrentRow# that would give me the number of the current row the cfoutput is on?  I could use that instead of my variable #loop_no# if that were the case.
0
 
LVL 2

Expert Comment

by:jonnygo55
ID: 9595105
true...that's another reason to use cfoutput...plus it is supposedly more efficient
0
 
LVL 2

Author Comment

by:David Williamson
ID: 9595116
so then I'm right about the #currentrow# variable?
0
 
LVL 2

Expert Comment

by:jonnygo55
ID: 9595119
yes
0
 
LVL 2

Author Comment

by:David Williamson
ID: 9595125
cool.  Thanks for the confirmation.  I'll wait to give you the points to see if anyone else has any more input, but don't worry, they're yours.
0
 
LVL 2

Expert Comment

by:jonnygo55
ID: 9595251
glad I could help
0
 
LVL 14

Assisted Solution

by:Renante Entera
Renante Entera earned 200 total points
ID: 9595296
I think jonnygo55 anwered your question regarding putting the result of a query in a list ...

But with regards to the code that you want to simplify, you can have it this way :

<cfset ButtonList = valueList(getButtons.names)>

<body onLoad="MM_preloadImages('Images/arch_flare.jpg')">
<table cellpadding="0" cellspacing="0" border="0" width="185">
     <tr>
     <td><cfoutput>
     <cfloop index="i" from=1 to="#ListLen(ButtonList)#">
     <a href="Index.cfm" onMouseOver="MM_swapImage('Image#i#','','Images/arch_flare.jpg',1)" onMouseOut="MM_swapImgRestore()">
      <img src="Images/#ListGetAt(ButtonList,i)#.jpg" name="Image#i#" width="185" height="25" border="0" id="Image#i#"></a><br>
     </cfloop></cfoutput>
     </td>
     </tr>
</table>
</body>

Regards!
eNTRANCE2002 :-)
0
 
LVL 2

Author Comment

by:David Williamson
ID: 9599022
Thanks, entrance2002, I was hoping to see an example of some different ideas on that.

I've settled on the following code, which I think simplifies the whole thing.  Lemme know what you think:

<table cellpadding="0" cellspacing="0" border="0" width="185">
      <tr>
      <td><cfoutput>
      <cfloop query="getButtons">
      <a href="#getButtons.link#" onMouseOver="MM_swapImage('Image#getButtons.currentrow#','','Images/arch_flare.jpg',1)" onMouseOut="MM_swapImgRestore()">
      <img src="Images/#getButtons.ButtonName#.jpg" name="Image#getButtons.currentrow#" width="185" height="25" border="0" id="Image#getButtons.currentrow#"></a><br>
      </cfloop></cfoutput>
      </td>
      </tr>
</table>
0
 
LVL 2

Author Comment

by:David Williamson
ID: 9599024
couple more points to spread around
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 9603329
Actually, you may still simplify your code without using the <cfloop> tag. Only <cfoutput> tag ...

Here's the simplification :

<table cellpadding="0" cellspacing="0" border="0" width="185">
     <tr>
     <td>
     <cfoutput query="getButtons">
     <a href="#link#" onMouseOver="MM_swapImage('Image#currentrow#','','Images/arch_flare.jpg',1)" onMouseOut="MM_swapImgRestore()">
     <img src="Images/#ButtonName#.jpg" name="Image#currentrow#" width="185" height="25" border="0" id="Image#currentrow#"></a><br>
     </cfoutput>
     </td>
     </tr>
</table>

And by the way, thanks for accepting my comments too.

Regards !
eNTRANCE2002 :-)
0
 
LVL 2

Author Comment

by:David Williamson
ID: 9606938
I can tell that great minds think alike, because I actually did that same coding change yesterday!  Cool...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Integration Management Part 2
Loops Section Overview
Suggested Courses

872 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