Coldfusion: Define CurrentRow in Structure/Array

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>
jabronicusAsked:
Who is Participating?
 
js_vaughanConnect With a Mentor Commented:
Unless I am mistaken, currentRow only Applies to a QUERY.  Instead, just use your CFLOOP index:

#ThisItem#
0
 
James RodgersConnect With a Mentor Web Applications DeveloperCommented:
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
 
jabronicusAuthor Commented:
Cool thanks for the help...Jester can you just give me a quick why on the cfqueryparam for future reference.  Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.