Hi everybody 
I am populating an array of structures with info for a product enquiry. 
<!--- ADD  PRODUCT TO CART ARRAY ROUTINE---> 
    <cfif IsDefined("btn_add")> 
    <a href="%5C"> 
    <cfset temp = arrayAppend(session.enquirycontents, structNew())> 
    <cfset session.enquirycontents[arrayLen(session.enquirycontents)].ID = #form.ID#> 
    <cfset session.enquirycontents[arrayLen(session.enquirycontents)].product = #productdetail.product#> 
     <cfset session.enquirycontents[arrayLen(session.enquirycontents)].prodnum = #productdetail.prodnum#> 
     <cfset session.enquirycontents[arrayLen(session.enquirycontents)].quantity = #form.Quantity#> 
     <cfset session.enquirycontents[arrayLen(session.enquirycontents)].dimensions = #productdetail.dimensions#> 
       <cflocation url="enquiryContents.cfm"> 
    </a> 
  </cfif> 
<!---FINISH ADDING TO CART ARRAY ROUTINE 

<!---FINISH ADDING TO CART ARRAY ROUTINE

as i add each product i want to check that a product has not allready been entered (ID doesnt exist)
i have tried all sorts of searches on the web but cant get someting simple like (ipe)does this new id already exist in the array and if so go to error page

Any help with this would be greatly appreciated

cheers and thanks in advance
Grabit

Thanks to you all

Recommended Answers

All 5 Replies

does this new id already exist in the array

If you're looking for a magic function, there isn't one. You must loop through the array elements one by one. Pull out each structure, check it's ID. If it matches throw an error. It's as simple as that.

Hi and thanks for the reply
Yes i kinda figured that but as i am completly new to array and how to handle them i would reaaly appreciate the code i need and just where to use it?

I have been strugling with now for days and days and i have finallly realised that i am floundering with something i really dont understand, so the code and an explanation of that code would really help me immensly
Cheers and again thanks for the reply
Grabit

I have still been fooling around with this but i still cant make it work
can someone PLEASE help with where im going wrong?

<!--- ADD  PRODUCT TO CART ARRAY ROUTINE--->
    <cfif IsDefined("btn_add")>
<!---is this ID already in the enquiry--->
    <cfset thisID = #form.ID#>
    <!---<cfdump var="#thisID#"><cfabort>--->
        <cfloop from="1" to="#arrayLen(session.enquirycontents)#" index="i">
        <cfif session.enquirycontents[i].ID eq #thisID#>
        <cflocation url="exists.cfm">    
        </cfif>
        </cfloop>
        <cfelse>
         <a href="%5C">
    <cfset temp = arrayAppend(session.enquirycontents, structNew())>
    <cfset session.enquirycontents[arrayLen(session.enquirycontents)].ID = #form.ID#>
    <cfset session.enquirycontents[arrayLen(session.enquirycontents)].product = #productdetail.product#>
    <cfset session.enquirycontents[arrayLen(session.enquirycontents)].prodnum = #productdetail.prodnum#>
    <cfset session.enquirycontents[arrayLen(session.enquirycontents)].quantity = #form.Quantity#>
    <cfset session.enquirycontents[arrayLen(session.enquirycontents)].dimensions = #productdetail.dimensions#>
    <cflocation url="enquiryContents.cfm">
       </a>
     </cfif>
<!---FINISH ADDING TO CART ARRAY ROUTINE--->

Cheers and thanks again in advance
ziggydog

The loop is exactly what you need to do. The only thing I see wrong is adding that cfelse in the middle. Get rid of it. This is what your code is actually saying. It doesn't make any sense.

<cfif IsDefined("btn_add")>
     form WAS submitted, check the array for FORM.ID value
<cfelse>
     when form WASN'T submitted, add form fields that don't even 
     exist to the session array? this makes no sense.
</cfif>

Thanks arrgh
That did the trick, it all works fine now
thanks for the reply again
cheers
Grabit

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.