timmah1 Posted April 22, 2009 Share Posted April 22, 2009 This code worked fine, but now it don't Can anybody tell me what's wrong? <?php $val=substr($val,0); $price = explode(",", $val); $tmp = number_format($price[1], 2); $total_price += $tmp; echo $total_price; ?> It use to work regardless if there was one or two values for price[1] Thanks in advance Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 22, 2009 Share Posted April 22, 2009 On the phone... A: Foo Bar, Inc. car repair service. How can I help you? B: Hi, my car is broken. How long time will it take for you to repair it and how much will it cost? Quote Link to comment Share on other sites More sharing options...
Maq Posted April 22, 2009 Share Posted April 22, 2009 Most popular way to debug, echo variables out. Here's your output, do you see what's going on here? $val = 12345; $val=substr($val,0); //12345 $price = explode(",", $val); //[0] => 12345 $tmp = number_format($price[1], 2); //0.00 $total_price += $tmp; //0 echo $total_price; //0 ?> Like Daniel is implying, we need more information. What did you change? What happens? How did it used to work (example)? etc... Quote Link to comment Share on other sites More sharing options...
timmah1 Posted April 22, 2009 Author Share Posted April 22, 2009 Guess if Daniel would of happened to explain it that way, I would've understood what they meant, my apologies for not posting enough code. <?php while (list ($name,$val) = @each ($_POST['package_'])) { $val=substr($val,0); $price = explode(",", $val); $tmp1 = $price[1]; $total_price += $tmp1; } echo $total_price; ?> The price of $_POST['package_'] is the second value Quote Link to comment Share on other sites More sharing options...
timmah1 Posted April 22, 2009 Author Share Posted April 22, 2009 I fixed it, naturally, it was my stupid mistake $price[1] was formatted this way $price1 = "$".number_format ($price, 2); So obviously, it can't add with the dollar sign Thanks 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.