[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Coldfusion: Define CurrentRow in Structure/Array

Posted on 2007-10-14
3
Medium Priority
?
1,388 Views
Last Modified: 2011-09-20
The following is code to display the contents of shopping cart. I would like to number my rows based on the content of the cart. I thought I would be able to use Session.CurrentRow but it comes as undefined.  What am I missing?

      <cfif IsDefined ('Session.Cart')>
        <cfset ordertotal = 0>
        <cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem">
        <cfoutput>
              <cfquery name="getItem" datasource="#DSN#">
            SELECT itemPrice,itemID,itemName
            FROM items
            WHERE itemID = '#Session.Cart.ItemID[ThisItem]#'
               </cfquery>
         <cfset total = 0>
         <cfset total = total + (getItem.itemPrice * Session.Cart.Qty[ThisItem]) >
       
        <tr>
          <td>#Session.Cart.CurrentRow#</td>
          <td>#Session.Cart.ItemName[ThisItem]#</td>
          <td>#Session.Cart.Qty[ThisItem]#</td>
          <td>#LSCurrencyFormat(total,'local')#</td>
        </tr>
       </cfoutput>

        <!---Create row for total--->
      <cfset ordertotal = ordertotal  + total>
      </cfloop>
     
        <tr>
          <td colspan="3">&nbsp;</td>
          <td><cfoutput>#ordertotal#</cfoutput></td>
        </tr>
      </tbody>
    </cfif>
0
Comment
Question by:jabronicus
3 Comments
 
LVL 10

Accepted Solution

by:
js_vaughan earned 1800 total points
ID: 20077044
Unless I am mistaken, currentRow only Applies to a QUERY.  Instead, just use your CFLOOP index:

#ThisItem#
0
 
LVL 25

Assisted Solution

by:James Rodgers
James Rodgers earned 200 total points
ID: 20077614
js_vaughn is correct, only thing i would add is use cfqueryparam in the query

<cfif IsDefined ('Session.Cart')>
      <cfset ordertotal = 0>
      <cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem">
            <cfoutput>
            <cfquery name="getItem" datasource="#DSN#">
                  SELECT itemPrice,itemID,itemName
                  FROM items
                  WHERE itemID = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Session.Cart.ItemID[ThisItem]#">
            </cfquery>
            <cfset total = 0>
            <cfset total = total + (getItem.itemPrice * Session.Cart.Qty[ThisItem]) >
            
            <tr>
            <td>#thisItem#</td>
            <td>#Session.Cart.ItemName[ThisItem]#</td>
            <td>#Session.Cart.Qty[ThisItem]#</td>
            <td>#LSCurrencyFormat(total,'local')#</td>
            </tr>
            </cfoutput>
            
            <!---Create row for total--->
            <cfset ordertotal = ordertotal  + total>
      </cfloop>
      
      <tr>
      <td colspan="3">&nbsp;</td>
      <td><cfoutput>#ordertotal#</cfoutput></td>
      </tr>
      </tbody>
</cfif>
0
 

Author Comment

by:jabronicus
ID: 20079850
Cool thanks for the help...Jester can you just give me a quick why on the cfqueryparam for future reference.  Thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question