[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

put results of a query into a list

Posted on 2003-10-21
15
Medium Priority
?
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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