2

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

2 Answers 2

9
<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)#">
Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.