Solved

put results of a query into a list

Posted on 2003-10-21
15
154 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

775 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