Re: Why doesn't working with array's ever stick in my thick head?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On May 9, 2008, at 1:05 PM, Dan Joseph wrote:

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?

The idea make sense, and I think it will work. But I'm getting this error:

[Fri May 9 13:19:33 2008] [error] PHP Fatal error: Unsupported operand types in /Volumes/RAIDer/webserver/Documents/dev/weightcalc/ index.php on line 22


foreach ($RoutePieces as $key => $value){
		$testWeight = $value * $PieceWeight; <-------Line 22
	}

Some quick trying tells me that the problem is my "*" I don't remember having this problem before. Is there another character I should use to multiply with? :)

Thanks for looking!



--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim@xxxxxxxxxx




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux