Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generating variables

Status
Not open for further replies.

izachar

Technical User
Oct 7, 2000
84
CA
I am creating variables:
<cfset index=1>

<cfoutput query=&quot;vacancy&quot;>

<cfset &quot;var#index#&quot; = #de_unit_number#& &quot;,red&&quot;>

<cfset index=index+1>

</cfoutput>

I need to then aggregate them in a cfinclude so it will look like this:

<cfinclude url=&quot;file?var1 var2&quot;>

I might have different number of vars every time.

Thank you for the help
 
For your <CFINCLUDE> you will need to build a string by concatenating the values of several variables. Since you may have a different number of variables each time the code executes, you will need to keep track of how many variables there are and what their names are so that you can assemble the string. I think that your variable &quot;index&quot; keeps the count and their names are &quot;var#index#&quot;. Because the token &quot;index&quot; is used in other contexts, I recommend that you change the name of that variable to something else, like &quot;counter&quot;, for clarity. To build the string, do something like this:

<cfset string = &quot;#file#?&quot;>
<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;#counter#&quot;>
<cfset string = string & evaluate(&quot;var#i#&quot;)>
</cfloop>

<cfinclude url=&quot;#string#&quot;>

I always have to fiddle and experiment when I use evaluate(), so the code above is probably not exactly correct, but you should be able to get the idea.
 
I actually solved it using a list:

<cfquery datasource=#datasource# username=#username# password=#password# name=&quot;vacancy&quot;>
select * from vacancy
</cfquery>


<cfset vacancy_indicator=&quot;&quot;>

<cfoutput query=&quot;vacancy&quot;>
<cfset vacancy_indicator=ListAppend(vacancy_indicator,&quot;#unit_number#=red&quot;,&quot;&amp;&quot;)>

</cfoutput>


<cflocation url=&quot;file.swt?#vacancy_indicator#&quot;>

thanks for the help any way
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top