[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Problems Defining an Array :'(

Asked by chrissp26 in ColdFusion Application Server

Tags: array, cfparam

Hello

I am building a website with an order list. This order list is similar to the basket of an ecommerce website it stores products to be used once the person has finished adding things. They then submit the order to us for processing.

I am using a session variable to capture and retain the information, but I am having sooooo much trouble with it i'm tempted to ditch the lot.

The code basically pulls the product information from the DB based on the ID stored in the URL. It then populates an array in a structure called Item. This array then retains all the information and can grow or shrink depending on the persons preference.

I opened the page to test it in firefox (and obviously the session/array wasn't defined) so I got an error. So I used Cfparam tags to define the values that it said were missing but I still get this error:

---------------------------------------------------------------------|
Element ORDERLIST.ITEM is undefined in SESSION.  
 
The error occurred in C:\Inetpub\wwwroot\www.thechalkboardcompany.co.uk\htdocs\orderList.cfm: line 64
---------------------------------------------------------------------|

All I want to do is be able to view the page without defining the Array because that should only be defined if someone adds something to it. Otherwise it should remain blank and display a message saying there's nothing here etc etc.

Ok enough rabbiting on here is the code:




---------------------------------------------------------------------|
<cfif URL.mode eq "add" and URL.prodID is not "" or URL.mode eq "set" and URL.prodID is not "">
      <cfquery name="getProducts" datasource="#dsl#">
            SELECT * FROM products WHERE productID=#URL.prodID#
      </cfquery>
</cfif>
<cfif URL.mode eq "add" and URL.prodID is not "">
      <cfif not isDefined("session.orderList")>
            <cfset session.orderList = StructNew()>
            <cfset session.orderList.Item = ArrayNew(1)>
      </cfif>
      <cfset listNumber = ArrayLen(session.orderList.Item) +1>
      <cfset session.orderList.Item[listNumber] = StructNew()>
      <cfset session.orderList.Item[listNumber].productName = getProducts.product>
      <cfset session.orderList.Item[listNumber].productID = getProducts.productID>
      <cfset session.orderList.Item[listNumber].qty = getProducts.minimumQty>
      <cfset session.orderList.Item[listNumber].costPerItem = getProducts.costPerItem>
      <cfset session.orderList.Item[listNumber].total = session.orderList.Item[listNumber].qty * session.orderList.Item[listNumber].costPerItem>
      <cflocation url="#thisPage#" addtoken="no">
<cfelseif mode eq "set" and URL.ID is not "">
      <cfif FORM.qty ge getProducts.minimumQty>
            <cfset session.orderList.Item[URL.ID].qty = FORM.qty>
            <cfset session.orderList.Item[URL.ID].total = session.orderList.Item[URL.ID].qty * session.orderList.Item[URL.ID].costPerItem>
      </cfif>
      <cflocation url="#thisPage#" addtoken="no">
<cfelseif mode eq "del" and URL.prodID is not "">
      <cfset arrayDeleteAt(session.orderList.Item, URL.ID)>
      <cflocation url="#thisPage#" addtoken="no">
<cfelseif mode eq "delAll">
      <cfset clearStruct = structClear(session.orderList)>
      <cflocation url="#thisPage#" addtoken="no">
</cfif>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Chalkboard Order List</title>
<link rel="stylesheet" href="/m.css" type="text/css" media="all">
<script language="javascript1.1" type="text/javascript">
function decision(message, url){

      if(confirm(message)) location.href = url;
}
</script>
</head>
<body>
<cfinclude template="/incHeader.cfm">
<div id="titleBar">
      <h2>Your Order List</h2>
</div>
<cfinclude template="/incUtilityBar.cfm">
<div id="container">
      <cfinclude template="/incLeftNav.cfm">
      <div id="content">
            <div class="floatLeft">
            <img src="img/content/headerRight.jpg" width="11" height="30" alt="" border="0" class="floatRight">
            <img src="img/content/headerLeft.jpg" width="11" height="30" alt="" border="0" class="floatLeft">
            <h2>Your Order List</h2>

            
            <table cellpadding="2" cellspacing="0" border="0" width="100%">
            <cfif isDefined("session.orderList")>
                  <cfset orderTotal = 0>
                  <cfloop index="idx" from="1" to="#ArrayLen(session.orderList.Item)#">
                        <cfif idx mod 2>
                           <cfset class="rowa">
                        <cfelse>
                           <cfset class="rowb">
                        </cfif>
                        <cfoutput>
                  <tr>
                        <td width="1"><a href="##" onClick="decision('Are you sure you want to delete this item?','<cfoutput>#thisPage#?mode=del&ID=#idx#&prodID=#session.orderList.Item[idx].productID#</cfoutput>')"><img src="/img/common/delete.gif" alt="Click here to delete the quote item" width="15" height="15" border="0"></a></td>
                        <td>#session.orderList.Item[idx].productName#</td>
                        <td>#session.orderList.Item[idx].productID#</td>
                        <td>#session.orderList.Item[idx].qty#</td>
                        <td>#session.orderList.Item[idx].costPerItem#</td>
                        <td>#session.orderList.Item[idx].total#</td>
                        <td><form action="#thisPage#?mode=set&ID=#idx#&prodID=#session.orderList.Item[idx].productID#" method="post"><input type="text" name="qty" value="#session.orderList.Item[idx].qty#" size="5"><input type="submit" value="update"></form></td>
                  </tr>
                        </cfoutput>
                        <cfset orderTotal = orderTotal + session.orderList.Item[idx].total>
                  </cfloop>
                  <cfset session.orderList.orderTotal = orderTotal>
                  <tr>
                        <td colspan="7" align="right">
                        <cfoutput>#orderTotal#</cfoutput>
                        </td>
                  </tr>
            <cfelse>
                  <tr>
                        <td align="center">There are no items in your order list.</td>
                  </tr>
            </cfif>
            </table>
            <a href="<cfoutput>#thisPage#?mode=delAll</cfoutput>">Delete all</a>
            
            </div>
      </div>
      <br clear="all">
      <div id="categoryFooter"><img src="img/leftNav/footer.gif" width="185" height="11" alt="" border="0"></div>
      <div id="contentFooter">
            <img src="img/content/footerRight.gif" width="11" height="11" alt="" border="0" class="floatRight">
            <img src="img/content/footerLeft.gif" width="11" height="11" alt="" border="0" class="floatLeft">
      </div>
</div>
</body>
</html>
---------------------------------------------------------------------|
 
Related Solutions
Keywords: Problems Defining an Array :'(
 
Loading Advertisement...
 
[+][-]02/16/06 08:41 AM, ID: 15972413Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: ColdFusion Application Server
Tags: array, cfparam
Sign Up Now!
Solution Provided By: mkishline
Participating Experts: 1
Solution Grade: A
 
[+][-]02/16/06 09:24 AM, ID: 15972878Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81