• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

element at position 2 cannot be found

Explorer ,
Oct 11, 2010 Oct 11, 2010

Copy link to clipboard

Copied

I have been beating my brains out trying to figure this out. If any of you have thoughts, I would love to hear them. I have a cflocation to redirect to PayPal as follows...

<cflocation url="https://www.paypal.com/cgi-bin/websrc?tax_cart=#WA_eCart_FormatNumber(WA_eCart_GetTax(whitcart), false, 2)#&no_note=0&no_shipping=1&return=http://xxxxxxxx.com/paypalsuccess.cfm&cmd=_cart&upload=1&currency_code=USD&address_override=0&firstn...), false, 2)#&

<cfoutput>

    <CFLOOP FROM='1' TO='#ArrayLen(session.whitcart_items)#' INDEX='i'>

        <CFLOOP COLLECTION='#session.whitcart_items#' ITEM='y'>

            <CFIF StructKeyExists(session.whitcart_items, y)>

                #y#=#session.whitcart_items#&

            </CFIF>

        </CFLOOP>

    </CFLOOP>

</cfoutput>

business=xxxxxx@xxxxxxx.com" />

When I run this, it comes back with element at position 2 cannot be found. The probem is that my array only has one item in it. I dumped it to the screen and see this...

Price=0.01 TotalPrice=0.01 Name=The_Day_After_His_Birth.pdf Weight=0 Description=The Day After His Birth FullDetails=1 The_Day_After_His_Birth.pdf (2) ID=2 TotalWeight=0 Quantity=1

So I am struggling as to what is occurring.

Thoughts?

TOPICS
Advanced techniques

Views

4.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 12, 2010 Oct 12, 2010

Copy link to clipboard

Copied

Is your array 1D or 2D?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 12, 2010 Oct 12, 2010

Copy link to clipboard

Copied

It is an array with a struct inside it. Here is a copy...

array

1
struct
DescriptionThe Day After His Birth
FullDetails1 The_Day_After_His_Birth.pdf (2)
ID2
NameThe_Day_After_His_Birth.pdf
Price0.01
Quantity1
TotalPrice0.01
TotalWeight0
Weight0

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 12, 2010 Oct 12, 2010

Copy link to clipboard

Copied

So in other words, it's a 1D array.  That means this line will never work:

#y#=#session.whitcart_items#

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 12, 2010 Oct 12, 2010

Copy link to clipboard

Copied

Dan Bracuk wrote:

So in other words, it's a 1D array.  That means this line will never work:

#y#=#session.whitcart_items#

Well it should work as long as 'i' is an integer in the set of {1} and 'y' is a string in the set of {'Description','FullDetails','ID',etc}

I.E this hard coded example should work.

<cfoutput>Description = #session.whitcart_items[1]["Description"]#</cfoutput>

Thus, this should also work.

<cfset i = 1>

<cfset y = "Description">

<cfoutput>#y# = #session.whitchat_items</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2010 Oct 12, 2010

Copy link to clipboard

Copied

Are you sure the error is occurring where you think it is? To find out, test by replacing the line

<CFLOOP FROM='1' TO='#ArrayLen(session.whitcart_items)#' INDEX='i'>

with

<CFLOOP FROM='1' TO='1' INDEX='i'>

Do you get the same error message? If so, does Coldfusion refer you to a line number where the error occurs?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 12, 2010 Oct 12, 2010

Copy link to clipboard

Copied

LATEST

Thanks for the input. I decided to go in a different direction by utilizing a cfc and calling the functions using ajax.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation