Solved

put results of a query into a list

Posted on 2003-10-21
15
152 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:theamzngq
  • 8
  • 5
  • 2
15 Comments
 
LVL 2

Author Comment

by:theamzngq
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 100 total points
ID: 9594984
#valueList(getButtons.names)# or in this case #quotedValueList(getButtons.names)#
0
 
LVL 2

Author Comment

by:theamzngq
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
 
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:theamzngq
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:theamzngq
ID: 9595116
so then I'm right about the #currentrow# variable?
0
Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

 
LVL 2

Expert Comment

by:jonnygo55
ID: 9595119
yes
0
 
LVL 2

Author Comment

by:theamzngq
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 50 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:theamzngq
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:theamzngq
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:theamzngq
ID: 9606938
I can tell that great minds think alike, because I actually did that same coding change yesterday!  Cool...
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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

21 Experts available now in Live!

Get 1:1 Help Now