Jump to content

[SOLVED] still having problem with adding up two totals


fazz

Recommended Posts

I have a shopping cart type site I have created and can't get past one problem, the user adds there items say comes to £485.00

 

Each user has a budget this one for instance has a budget of 485.00

 

So they add it to their cart and the site tells them they have '0' budget left, if they then add another item for 595.00 it then says they have £484.00 left to spend. I have put other posts on here but I am a newbee! and I can't work out why it won't work or how to correct it.

 

<?php
				//Add up toal items and - from Budget cost: does not work correctley over 999.00
              $Budget = $HTTP_GET_VARS['Budget'];
		  $TotalCart = $HTTP_SESSION_VARS["icNamco"]->col("Total");
              $BudgetRemain = $Budget - $TotalCart;
		  echo number_format ($BudgetRemain, 0, "", ",");
		  ?>

 

can someone please help!!!

Link to comment
Share on other sites

hi mate its a crude fix but you could use something simple like..

if ($TotalCart + $ItemPrice > $BudgetRemain){
    echo "<font color='red'>you have exceeded your budget</font>"; }
else {
    echo number_format ($BudgetRemain, 0, "", ",");
} 

 

Note: this has not been error checked so it may not work :P

Link to comment
Share on other sites

Thanks, thats close to what I want to end up with, but I need to keep a record of how much the user goes over budget.

 

I thnk I have found my problem the "$HTTP_SESSION_VARS["icNamco"]->col("Total");

" comes in as 1,070.00 instead of 1070.00 which seems to cause the problem I am having. I am looking on php.net to see if I can convert it so it comes in as 1070.00.

 

As yet I can't find a solution if any one can help!

Link to comment
Share on other sites

Ok I tried this with no result:

 

<?php

             $Budget = $HTTP_GET_VARS['Budget'];
$TotalCart = $HTTP_SESSION_VARS["icNamco"]->col("Total");
             $TotalCartB = str_replace(",","","$TotalCart");
             $BudgetRemain = $Budget - $TotalCart;
echo number_format ($BudgetRemain, 2, '.', '');
		  ?>

Link to comment
Share on other sites

tELL A LIE GOT IT TO WORK THANKS!!!!!

 

 

<?php
				//Add up toal items and - from Budget cost: WORKS!
              $Budget = $HTTP_GET_VARS['Budget'];
		  $TotalCart = $HTTP_SESSION_VARS["icNamco"]->col("Total");
		  $TotalCartB = str_replace(",","","$TotalCart");
              $BudgetRemain = $Budget - $TotalCartB;
		  echo number_format ($BudgetRemain, 2, '.', '');
		  ?>

 

PERFECT

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.