Jump to content

Val addition


timmah1

Recommended Posts

Can you do a print_r on $_POST['package_'] so we can see exactly what is being processed.

 

I just tried:

 

<?php
$package=array("bread"=>"89.99,wed","cheese"=>"30.00,fri");
$total=0;

while (list ($name,$val) = @each ($package)) {     
      $raw = "$val";
      $price = explode(",", $raw);
      $total += $price[0];
  }
echo $total;
?>

 

which from your earlier comments is what i think the structure of $_POST['package_'] would give and I get the correct total.  Thats why i think your while loop is actually ok and there is another problem...

Link to comment
Share on other sites

Yesideez,

You are my hero!

 

This is the final code

while (list ($name,$val) = @each ($_POST['package_'])) {     
		$val=substr($val,1);
	  $price = explode(",", $val);
	  $tmp = $price[0];
	  $total += $tmp;

 

And it gives me a total now

 

Thank you so much for your patience

 

Mad Mick, thank you for your help as well, but the $_POST['package_'] has always worked ok

Link to comment
Share on other sites

This might be safer...

while (list ($name,$val) = @each ($_POST['package_'])) {     
        $price = explode(",", $val);
        $total += substr($price[0],1);

 

Give it a whirl and see...

 

Where you had it before it was stripping the first character off each element in the array and the display looks a bit strange with the first character missing.

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.