Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to create a sub total and grand total?

Posted on 2008-06-22
7
Medium Priority
?
805 Views
Last Modified: 2008-06-23
Ive created a ver simple shopping cart (see below), i wanting to add a sub total on each line of the looping table then a grand total in the last table cell which sits outside of the loop. how can i do this please?

sorry about posting so much code but i though it was best for you to see it all.
<th>Your Shopping Cart</th>
  <th>Value each</th>
  <th>Colour</th>
  <th>Size</th>
  <th>Qty</th>
  <th>Subtotal</th>
</tr>
<cfloop query="getCart">
  <tr>
    <td>
   	#getCart.item_name#    </td> 
    <td>#getCart.amount#</td>
    <td>#getCart.on0#</td>
    <td>#getCart.on1#</td>
    <td>
      <input type="hidden" name="item_number" value="#getCart.item_number#" />
      <input type="text" size="3" name="quant_#getCart.item_number#" 
           value="#getCart.Quantity#" /></td>
    <td></td>
  </tr>
 
 
</cfloop>
<tr>
    <td colspan="4">&nbsp;</td>
    <th>Total:</th>
    <td></td>
  </tr>
</table>
<input type="hidden" name="doaction" value="updateCart" />
<input type="submit" name="submit" value="Update Quantities">
</form>
 
 
 
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="submit" name="submit" value="Check Out">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="ecoLife.me.uk" value="sales@ecolife.me.uk">
<cfloop query="getCart">
<input type="hidden" name="item_name_#getCart.currentrow#" value="#getCart.item_name#">
<input type="hidden" name="item_number_#getCart.currentrow#" value="#getCart.item_number#">
<input type="hidden" name="quantity_#getCart.currentrow#" value="#getCart.quantity#">
<input type="hidden" name="amount_#getCart.currentrow#" value="#getCart.amount#">
<input type="hidden" name="handling_#getCart.currentrow#" value="#getCart.handling#">
<input type="hidden" name="shipping_#getCart.currentrow#" value="#getCart.shipping#">
<input type="hidden" name="shipping2_#getCart.currentrow#" value="#getCart.shipping2#">
<input type="hidden" name="on0_#getCart.currentrow#" value="#getCart.on0#">
<input type="hidden" name="os0_#getCart.currentrow#" value="#getCart.os0#">
<input type="hidden" name="on1_#getCart.currentrow#" value="#getCart.on1#">
<input type="hidden" name="os1_#getCart.currentrow#" value="#getCart.os1#">
</cfloop>
<input type="hidden" name="page_style" value="PayPal">
<input type="hidden" name="return" value="http://#cgi.server_name##request.path#?doaction=completeCart">
<input type="hidden" name="cancel_return" value="http://#cgi.server_name##request.path#?doaction=cancelCart">
<input type="hidden" name="cn" value="Comments">
<input type="hidden" name="currency_code" value="GBP">
</form>

Open in new window

0
Comment
Question by:bede123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 21841987
Like this:
<cfset grandTotal = 0 >
 
<th>Your Shopping Cart</th>
  <th>Value each</th>
  <th>Colour</th>
  <th>Size</th>
  <th>Qty</th>
  <th>Subtotal</th>
</tr>
<cfloop query="getCart">
  <tr>
    <td>
   	#getCart.item_name#    </td> 
    <td>#getCart.amount#</td>
    <td>#getCart.on0#</td>
    <td>#getCart.on1#</td>
    <td>
      <input type="hidden" name="item_number" value="#getCart.item_number#" />
      <input type="text" size="3" name="quant_#getCart.item_number#" 
           value="#getCart.Quantity#" /></td>
    <cfset itemTotal = getCart.amount * getCart.Quantity >
    <cfset grandTotal = grandTotal + itemTotal >
    <td align="right">#NumberFormat(itemTotal,"0.99")#</td>
  </tr>
 
 
</cfloop>
<tr>
    <td colspan="4">&nbsp;</td>
    <th>Total:</th>
    <td align="right">#NumberFormat(grandTotal,"0.99")#</td>  </tr>
</table>
<input type="hidden" name="doaction" value="updateCart" />
<input type="submit" name="submit" value="Update Quantities">
</form>

Open in new window

0
 
LVL 1

Author Comment

by:bede123
ID: 21845357
thats great thanks, so how would i chnage the format to '£' ?

thanks for your wuick response.

zac
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21846692
Can you show me how the £ format would look for example for: 123.45

0
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
LVL 1

Author Comment

by:bede123
ID: 21846841
it would just look like:

123.45 would be £123.45
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21846879
Check this:

<td align="right">£#NumberFormat(grandTotal,"0.99")#</td>  </tr>
0
 
LVL 1

Author Comment

by:bede123
ID: 21846911
ok so just as simple as that! perhaps i was tryign to make it to completcated, thanks again
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21847006
:)
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

636 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