fazz Posted December 18, 2007 Share Posted December 18, 2007 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!!! Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 18, 2007 Share Posted December 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
fazz Posted December 18, 2007 Author Share Posted December 18, 2007 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! Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 18, 2007 Share Posted December 18, 2007 just do str_replace(",","","1,070.00"); Quote Link to comment Share on other sites More sharing options...
fazz Posted December 18, 2007 Author Share Posted December 18, 2007 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, '.', ''); ?> Quote Link to comment Share on other sites More sharing options...
fazz Posted December 18, 2007 Author Share Posted December 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.