On Fri, May 9, 2008 at 12:56 PM, Jason Pruim <japruim@xxxxxxxxxx> wrote: > Hi Everyone, > > SO it's friday, I'm tired, and I can't seem to think straight... I am > attempting to do some very basic math with some arrays... Here's the pseudo > code that I'm working with: > > NumberOfPieces * PieceWeight = TotalWeight > > explode total weight to get tenth's of pounds, then divide tenth's of > pounds by 16 to grab ounces. > > Display TotalWeight # Exploded Ounces. > > Which I have working just fine for a single set of boxes... > > My problem is I want to be able to automatically add say 50 boxes in a form > to process the weight of each route... > > So what I need to do is probably use some kind of a counter to loop through > my $RoutePieces array and multiply by the $PieceWeight? $PieceWeight is a > static number. > > Now let me show you some abbreviated code to try and explain what I'm using > right now: > <?PHP > $i= "0"; > $num= "2"; > $PieceWeight = $_POST['txtPieceWeight']; > $RoutePieces[] = $_POST['txtRoutePieces']; > $RouteNumber[] = $_POST['txtRoute']; > > $totalWeight = $PieceWeight * $RoutePieces/16; > $weightExplode = explode('.', $totalWeight); > //$weightOunces = ((float)('.' . $weightExplode[1])) * 16; > // Use stut's method... Seems cleaner > $explodeOunces = ($totalWeight - intval($totalWeight)) * 16; > > while($i <= $num){ > echo <<<HTML > > <p> > Route Number:<input type="text" name="txtRoute[$i]" size="4" value > ="{$RouteNumber[$i]}"> Number of pieces: <input type="text" > name="txtRoutePieces[$i]" size="4" value="{$RoutePieces[$i]}"><label>Total > weight of route: {$weightExplode[0]} # {$explodeOunces} Ounces</label> > </p> > > > HTML; > > $i++; > echo $i; > } > ?> > > the $_POST array has the proper values stored properly... I just can't seem > to figure out how to work with the values... Any ideas? Or slaps on the back > of the head to wake me up a little? :) > > I need help :P > > > > -- > > Jason Pruim > Raoset Inc. > Technology Manager > MQC Specialist > 3251 132nd ave > Holland, MI, 49424-9337 > www.raoset.com > japruim@xxxxxxxxxx > > > > Rather than a counter, you could use foreach: foreach ( $RoutePieces as $key => $value ) { $blah = $value * $PieceWeight; } Make sense? -- -Dan Joseph www.canishosting.com - Plans start @ $1.99/month. Reseller plans and Dedicated servers available. "Build a man a fire, and he will be warm for the rest of the day. Light a man on fire, and will be warm for the rest of his life."