Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loops and next 5 records

Status
Not open for further replies.

mmmm

Programmer
Jan 15, 2001
1
GB
I have a loop that totals values submitted from a form. A query outputs a number of fields, to which a name is assigned by going through a list. then the loop sees which checkboxes have been checked and creates totals from the checkboxes that correspond to each field. My problem is that i have created a next 5 button that submits to the same page it is on, and therefore goes through the list and does the totals again! any ideas how to stop it doing that? i have named the next 5 button so i can say
<cfif isdefined(&quot;nextstart&quot;)>
then dont retotal, use previous totals, but cant work out what should go in here!
</cfif>

here is the code that totals the values and assigns a session variable.....

<CFLOOP QUERY=&quot;QSections&quot;>

<!--- For each section record... --->
<cfset total=0> <!--- Initialise total --->
<CFSET SrchName=&quot;SrchCat&quot;&amp;QSections.CurrentRow> <!--- Create form variable name --->
<CFSET SessName=&quot;session.SrchCat&quot;&amp;QSections.CurrentRow>
<!--- <TD>#secName#</TD><TD>#SrchName#-</TD> ---> <!--- Show section name and form variable name --->
<CFIF IsDefined(&quot;#SrchName#&quot;)> <!--- If form variable was passed from search page, e.g. SrchCat1, SrchCat2, etc. --->
<CFSET theList=Evaluate(SrchName)> <!--- Assign to theList string of numbers from search page --->
<!--- <TD> --->
<cfloop index=&quot;num&quot; list=#theList#> <!--- Loop the list --->
<cfset total=total + num> <!--- accumulate values --->
<!--- #num#, ---> <!-- show current value in table -->
</cfloop>
<CFSET &quot;#SessName#&quot;=#total#>

<!--- </TD>
<TD>#total#</TD> --->
<!-- Show total in table -->
<CFELSE>
<!--- <TD>not passed from search page.</TD> ---><TD> </TD> <!-- Does not exist --><CFSET &quot;#SessName#&quot;=0>
</cfif>
</cfloop>
 
I'm not sure I understand what the problem is. It sounds like your code is calculating totals correctly and you know how to determine if the &quot;Next&quot; button was used to get to the page so what are you having trouble coding? If it's just a matter of getting the totals from the session variables, this should work.

<CFLOOP QUERY=&quot;QSections&quot;>
#evaluate(&quot;session.SrchCat#QSections.CurrentRow#&quot;)#
</cfloop>

GJ
 
think the other way ;-)

<cfif isdefined(&quot;nextstart&quot;)>
then dont retotal, use previous totals, but cant work out what should go in here!
</cfif>

now try this instead :

<cfif NOT isdefined(&quot;nextstart&quot;)>
then retotal</cfif>

or even :

<cfif isdefined(&quot;nextstart&quot;)>
then total=previous totals
</cfif>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top