David Williamson
asked on
put results of a query into a list
with the follwing code:
<cfquery datasource="wrightdb" name="getButtons">
SELECT ButtonName as names FROM NavLeftButtons
</cfquery>
<cfoutput query="getButtons">#getBut tons.names #</cfoutpu t>
The page disply looks like:
button1button2button3butto n4
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.
<cfquery datasource="wrightdb" name="getButtons">
SELECT ButtonName as names FROM NavLeftButtons
</cfquery>
<cfoutput query="getButtons">#getBut
The page disply looks like:
button1button2button3butto
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
What do you think about my second code post? A better way to accomplish the same thing?
that'll work...
I would use <cfoutput query="getButtons"> instead of <cfloop... as a matter of practice
I would use <cfoutput query="getButtons"> instead of <cfloop... as a matter of practice
ASKER
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.
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.
true...that's another reason to use cfoutput...plus it is supposedly more efficient
ASKER
so then I'm right about the #currentrow# variable?
yes
ASKER
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.
glad I could help
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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#get Buttons.cu rrentrow#' ,'','Image s/arch_fla re.jpg',1) " onMouseOut="MM_swapImgRest ore()">
<img src="Images/#getButtons.Bu ttonName#. jpg" name="Image#getButtons.cur rentrow#" width="185" height="25" border="0" id="Image#getButtons.curre ntrow#"></ a><br>
</cfloop></cfoutput>
</td>
</tr>
</table>
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(
<img src="Images/#getButtons.Bu
</cfloop></cfoutput>
</td>
</tr>
</table>
ASKER
couple more points to spread around
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#cur rentrow#', '','Images /arch_flar e.jpg',1)" onMouseOut="MM_swapImgRest ore()">
<img src="Images/#ButtonName#.j pg" 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 :-)
Here's the simplification :
<table cellpadding="0" cellspacing="0" border="0" width="185">
<tr>
<td>
<cfoutput query="getButtons">
<a href="#link#" onMouseOver="MM_swapImage(
<img src="Images/#ButtonName#.j
</cfoutput>
</td>
</tr>
</table>
And by the way, thanks for accepting my comments too.
Regards !
eNTRANCE2002 :-)
ASKER
I can tell that great minds think alike, because I actually did that same coding change yesterday! Cool...
ASKER
<body onLoad="MM_preloadImages('
<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(
<img src="Images/#getButtons.Bu
</cfloop></cfoutput>
</td>
</tr>
</table>
</body>
So I guess my new/additional question would be, how could I write this code better?