If you want them all to be accessible individually, you can build  
them all out as an array of associative arrays:

<!--- Fake query --->
<cfset myQuery = queryNew("contactId,firstname,lastname") />
<cfset queryAddRow(myQuery) />
<cfset querySetCell(myQuery, "contactId", 1, 1) />
<cfset querySetCell(myQuery, "firstname", "Jimi", 1) />
<cfset querySetCell(myQuery, "lastname", "Hendrix", 1) />
<cfset queryAddRow(myQuery) />
<cfset querySetCell(myQuery, "contactId", 2, 2) />
<cfset querySetCell(myQuery, "firstname", "Joe", 2) />
<cfset querySetCell(myQuery, "lastname", "Satriani", 2) />

<!--- Output as JS array --->
<cfoutput>
<script>
var guitarPlayers = [];

<cfloop query="myQuery">
        <cfsilent>
                <cfset player = "{" />
                <cfloop list="#myQuery.columnList#" index="column">
                        <cfset player = player & lCase(column) & ":""" & 
myQuery[column] 
[myQuery.currentRow] & """" />
                        <cfif column neq listLast(myQuery.columnList)>
                                <cfset player = player & "," />
                        </cfif>
                </cfloop>
                <cfset player = player & "}" />
        </cfsilent>
        guitarPlayers[guitarPlayers.length] = #player#;
</cfloop>       

alert(guitarPlayers);
alert(guitarPlayers[0].firstname);
</script>
</cfoutput>

You can also use <cfwddx> to automatically change the query into a JS  
variable.

-Joe


On Apr 5, 2007, at 5:15 AM, Adrian Lynch wrote:

> It depends where you what to put them. If you want them in the same  
> element
> in the JS array build the string as you want it in the output:
>
> yourArray[#yourQuery.CurrentRow - 1#] = 'This is column 1:
> #youQuery.Column1# and this is column 2: #youQuery.Column2#';
>
> Adrian
>
> -----Original Message-----
> From: Danny Metfield [mailto:[EMAIL PROTECTED]
> Sent: 04 April 2007 15:23
> To: CF-Newbie
> Subject: Re: dynamic js arrays
>
>
> Thank you
>
> A few more ?s
>
>
> What if I need to add more than one column?
> How do i reference these array values in my code?
>
>
>
>> <script>
>>      var yourArray = [];
>>      <cfoutput query="yourQuery">
>>              yourArray[#yourQuery.CurrentRow - 1#] = '#youQuery.ColumnName#';
>>      </cfoutput>
>> </script>
>>
>> Adrian
>>
>> -----Original Message-----
>> From: Danny Metfield [mailto:[EMAIL PROTECTED]
>> Sent: 04 April 2007 00:53
>> To: CF-Newbie
>> Subject: dynamic js arrays
>>
>>
>> hello
>>
>> newbie here
>>
>> I need to create a dynamic javascript array populated by results  
>> from a
>> query.
>>
>> Any suggestions?
>>
>> dmet
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Deploy Web Applications Quickly across the enterprise with ColdFusion MX7 & 
Flex 2
Free Trial 
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJU

Archive: 
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:2682
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15

Reply via email to