Can anyone help me ????? i just can't get the array to
grow by the next element ! bacicall the user enters a
Purchase Order and i have cobbled a 'SHOPPING CART' model to
create an array and a structure within it.
Well everything works except when the user tries to
enter the next set of details for the next line of the Purchase order the array won't grow (ie
from cartarray[1] to cartarray [2]) and just over
rights the orginal details.
The application.cfm sets up the object. The porders.cfm both calls the function and then posts the form values back to the same page which then trigers the function block. The function calls the component which creates the array and structure.
It could be a typo or that i am tring to do something
CF can't deal with. I have posted all my code and have hacked it to pieces in despreation tring to get it to work.
Any ideas folks
<<<<<<<<<<<<<<<<<<<Application..cfm>>>>>>>>>>>>>>>>>>>
<cfapplication clientmanagement="yes"
sessionmanagement="yes" name="havana">
<cfif not isdefined("session.myshoppingcary"
>
<cfobject name="session.myshoppingcart"
component="porders">
</cfif>
<<<<<<<<<<<<<<<<<Porders_dsp.cfm>>>>>>>>>>>>>>>>>>>>>
Calling page
<cfparam name="url.rownumber" default="1"
type="numeric">
<cfparam name="form.analysis" default="71801">
<cfparam name="form.description" default="">
<cfparam name="form.quantity" default="1">
<cfparam name="form.rate" default="0">
<---!tests to see if the form has been posted--->
<cfif #form.rate# neq 0>
<cfinvoke
component="#session.myshoppingcart#"
method="add"
rownumber ="#url.rownumber#"
analysis = "#form.analysis#"
description="#form.description#"
quantity="#form.quantity#"
rate="#form.rate#">
</cfif>
<---! post the form values back to the top of the page --->
<form action=" Porders_dsp.cfm ?action=Add&rownumber=
<cfoutput>#url.rownumber#</cfoutput>"
method="post">
<table width="653" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th width="10%" align="center">Analysis</th>
<th width="60%" align="center">Description</th>
<th width="10%" align="center">Quanity</th>
<th width="10%" align="center">Rate £</th>
<td width="10%"></td>
</tr>
<tr>
<td width="10%"><input id="analysis" name="Analysis"
size="7"></td>
<td width="60%"><input name="description"
size="60"></td>
<td width="10%"><input name="quantity" size="7"></td>
<td width="10%"><input name="rate" size="7"></td>
<td width="10%"><input
type="submit"value="SUBMIT"></td>
</tr>
</table>
</form>
<CFSET URL.ROWNUMBER= URL.ROWNUMBER+1>
<cfset poarray= session.myshoppingcart.list()>
<<<<<<<<<<<<<<<PORDERS.CFC>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<cfcomponent>
<CFSET THIS.CARTARRAY= ARRAYNEW(1)>
<cffunction access="public" name="add" output="false"
returntype="array">
<cfargument name="rowNumber" type="numeric"
required="yes" default="1">
<cfargument name="analysis" type="numeric"
required="no" default="0">
<cfargument name="description" type="string"
required="no" default="">
<cfargument name="quantity" type="numeric"
required="no" default="1">
<cfargument name="rate" type="numeric" required="no"
default="0">
<cfif arraylen(this.cartarray) gt 0>
<cfset cartitem =
this.cartarray[arraylen(this.cartarray)]>
<cfelse>
<cfset cartitem = structnew()>
</cfif>
<cfset cartitem.rowNumber=Arguments.rowNumber>
<cfset cartitem.analysis=Arguments.analysis>
<cfset cartitem.description=Arguments.description>
<cfset cartitem.quantity=Arguments.quantity>
<cfset cartitem.rate=Arguments.rate>
<cfset arrayappend(this.cartarray, cartitem)>
<cfreturn this.cartArray>
</cffunction>
<cffunction
name="list"
hint="This should list all the items in the array"
returntype="query">
<cfset
q=querynew("rownumber,description,analysis,quantity,rate"
>
<cfoutput>
<cfloop from="1" to="#arraylen(this.cartarray)#"
index="i">
<table>
<tr>
<td><cfset queryaddrow(q)></td>
<td><cfset querysetcell(q, "rownumber",
this.cartarray.rownumber)></td>
<td><cfset querysetcell(q, "description",
this.cartarray.description)></td>
<td><cfset querysetcell(q, "analysis",
this.cartarray.analysis)></td>
<td><cfset querysetcell(q, "quantity",
this.cartarray.quantity)></td>
<td><cfset querysetcell(q, "rate",
this.cartarray.rate)></td>
</tr>
</table></cfloop></cfoutput>
<cfdump var="#session.myshoppingcart#">
<cfreturn q>
</cffunction>
ibearian.
PROJECT H
mailto:ibearian@projecth.co.uk
grow by the next element ! bacicall the user enters a
Purchase Order and i have cobbled a 'SHOPPING CART' model to
create an array and a structure within it.
Well everything works except when the user tries to
enter the next set of details for the next line of the Purchase order the array won't grow (ie
from cartarray[1] to cartarray [2]) and just over
rights the orginal details.
The application.cfm sets up the object. The porders.cfm both calls the function and then posts the form values back to the same page which then trigers the function block. The function calls the component which creates the array and structure.
It could be a typo or that i am tring to do something
CF can't deal with. I have posted all my code and have hacked it to pieces in despreation tring to get it to work.
Any ideas folks
<<<<<<<<<<<<<<<<<<<Application..cfm>>>>>>>>>>>>>>>>>>>
<cfapplication clientmanagement="yes"
sessionmanagement="yes" name="havana">
<cfif not isdefined("session.myshoppingcary"
<cfobject name="session.myshoppingcart"
component="porders">
</cfif>
<<<<<<<<<<<<<<<<<Porders_dsp.cfm>>>>>>>>>>>>>>>>>>>>>
Calling page
<cfparam name="url.rownumber" default="1"
type="numeric">
<cfparam name="form.analysis" default="71801">
<cfparam name="form.description" default="">
<cfparam name="form.quantity" default="1">
<cfparam name="form.rate" default="0">
<---!tests to see if the form has been posted--->
<cfif #form.rate# neq 0>
<cfinvoke
component="#session.myshoppingcart#"
method="add"
rownumber ="#url.rownumber#"
analysis = "#form.analysis#"
description="#form.description#"
quantity="#form.quantity#"
rate="#form.rate#">
</cfif>
<---! post the form values back to the top of the page --->
<form action=" Porders_dsp.cfm ?action=Add&rownumber=
<cfoutput>#url.rownumber#</cfoutput>"
method="post">
<table width="653" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th width="10%" align="center">Analysis</th>
<th width="60%" align="center">Description</th>
<th width="10%" align="center">Quanity</th>
<th width="10%" align="center">Rate £</th>
<td width="10%"></td>
</tr>
<tr>
<td width="10%"><input id="analysis" name="Analysis"
size="7"></td>
<td width="60%"><input name="description"
size="60"></td>
<td width="10%"><input name="quantity" size="7"></td>
<td width="10%"><input name="rate" size="7"></td>
<td width="10%"><input
type="submit"value="SUBMIT"></td>
</tr>
</table>
</form>
<CFSET URL.ROWNUMBER= URL.ROWNUMBER+1>
<cfset poarray= session.myshoppingcart.list()>
<<<<<<<<<<<<<<<PORDERS.CFC>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<cfcomponent>
<CFSET THIS.CARTARRAY= ARRAYNEW(1)>
<cffunction access="public" name="add" output="false"
returntype="array">
<cfargument name="rowNumber" type="numeric"
required="yes" default="1">
<cfargument name="analysis" type="numeric"
required="no" default="0">
<cfargument name="description" type="string"
required="no" default="">
<cfargument name="quantity" type="numeric"
required="no" default="1">
<cfargument name="rate" type="numeric" required="no"
default="0">
<cfif arraylen(this.cartarray) gt 0>
<cfset cartitem =
this.cartarray[arraylen(this.cartarray)]>
<cfelse>
<cfset cartitem = structnew()>
</cfif>
<cfset cartitem.rowNumber=Arguments.rowNumber>
<cfset cartitem.analysis=Arguments.analysis>
<cfset cartitem.description=Arguments.description>
<cfset cartitem.quantity=Arguments.quantity>
<cfset cartitem.rate=Arguments.rate>
<cfset arrayappend(this.cartarray, cartitem)>
<cfreturn this.cartArray>
</cffunction>
<cffunction
name="list"
hint="This should list all the items in the array"
returntype="query">
<cfset
q=querynew("rownumber,description,analysis,quantity,rate"
<cfoutput>
<cfloop from="1" to="#arraylen(this.cartarray)#"
index="i">
<table>
<tr>
<td><cfset queryaddrow(q)></td>
<td><cfset querysetcell(q, "rownumber",
this.cartarray.rownumber)></td>
<td><cfset querysetcell(q, "description",
this.cartarray.description)></td>
<td><cfset querysetcell(q, "analysis",
this.cartarray.analysis)></td>
<td><cfset querysetcell(q, "quantity",
this.cartarray.quantity)></td>
<td><cfset querysetcell(q, "rate",
this.cartarray.rate)></td>
</tr>
</table></cfloop></cfoutput>
<cfdump var="#session.myshoppingcart#">
<cfreturn q>
</cffunction>
ibearian.
PROJECT H
mailto:ibearian@projecth.co.uk