开发者

Creating array in coldfusion

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 ex开发者_Go百科ists in the following format

SKU82328  QTY 1
SKU9832   QTY 3
SKU8923   QTY 1

skulist=SKU82328,SKU9832,SKU8923&quantitylist=1,3,1


<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)#">


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>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜