Reputation: 173
How would I create an array that will return data in the following format via CF 8?
This information originates from an order table based on SKU value and QTY. I already know the query to use to pull the data. I just would like some help to format it.
The original data exists in the following format
SKU82328 QTY 1
SKU9832 QTY 3
SKU8923 QTY 1
skulist=SKU82328,SKU9832,SKU8923&quantitylist=1,3,1
Upvotes: 2
Views: 1189
Reputation: 338208
<cfquery name"SkuQuery" datasource="DSN">
SELECT sku, quantity FROM someTable WHERE someCondition = 'true'
</cfquery>
<cfset SkuList = ValueList(SkuQuery.sku)>
<cfset QuantityList = ValueList(SkuQuery.quantity)>
<cfset QueryString = "skulist=#URLEncodedFormat(SkuList)#&quantitylist=#URLEncodedFormat(QuantityList)#">
Upvotes: 9
Reputation: 9942
I think you would have to do something like below
<!--- Do the query --->
<cfquery name="test" datasource="cfsnippets"> SELECT Emp_ID, LastName, FirstName, Email FROM Employees </cfquery>
<!--- Declare the array ---> <cfset myarray=arraynew(2)>
<!--- Populate the array row by row --->
<cfloop query="test"> <cfset myarray[CurrentRow][1]=Emp_ID> <cfset myarray[CurrentRow][2]=LastName> <cfset myarray[CurrentRow][3]=FirstName> <cfset myarray[CurrentRow][4]=Email> </cfloop>
<!--- Now, create a loop to output the array contents --->
<cfset total_records=test.recordcount>
<cfloop index="Counter" from=1 to="#Total_Records#">
<cfoutput> ID: #MyArray[Counter][1]#, LASTNAME: #MyArray[Counter][2]#, FIRSTNAME: #MyArray[Counter][3]#, EMAIL: #MyArray[Counter][4]# <br>
</cfoutput> </cfloop>
Upvotes: 0