Solved

put results of a query into a list

Posted on 2003-10-21
15
151 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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Join & Write a Comment

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

13 Experts available now in Live!

Get 1:1 Help Now