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!!!

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

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!

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, '.', '');
		  ?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.