|
 |
beginning_php thread: Fatal error:unsupported operand type.....huh?
Message #1 by peter@p... on Mon, 16 Sep 2002 22:42:09
|
|
Here's the offending code:
[php]
$cpp += (($_POST['tfUnit'][$i] * $cVal) * ($_POST['tfAmt'][$i] *
100)/100);
[/php]
$cVal is either 0 or a value returned from a function.
Since everything resolves to a number here, theoretically, what's up with
this errror?
Message #2 by peter@p... on Mon, 16 Sep 2002 22:47:47
|
|
To clarify:
Well, perhaps I'm going about this incorrectly, but ideally I'd like to
roll-up a total for $cpp; the If - else is there because the function
compares a value passed to determine if the value is present in a lookup
array, if so, then it does some calculations and returns either 0 or the
result of the calculations.
[code]
$cpp = 0;
for($i = 0; $i < $_SESSION['numIng']; ++$i)
{
$portion = explode(":" , $_POST['selMeasure'][$i]);
$cVal = getConversionValue($_POST['tfUnit'][$i], $portion[0],
$portion[1]);
if($cVal !=0)
{
$cpp += ($_POST['tfUnit'][$i] * $cVal) * ($_POST['tfAmt']
[$i] * 100)/100;
}
else
{
$cpp += ($_POST['tfUnit'][$i] * $portion[1]) * ($_POST
['tfAmt'][$i] * 100)/100;
}
}
[/code]
Message #3 by "Nikolai Devereaux" <yomama@u...> on Mon, 16 Sep 2002 14:52:31 -0700
|
|
My first suggestion would be to break apart all the operations to see which
one is giving you the error.
$cpp = 0;
for($i = 0; $i < $_SESSION['numIng']; ++$i)
{
$portion = explode(":" , $_POST['selMeasure'][$i]);
$cVal = getConversionValue($_POST['tfUnit'][$i],
$portion[0],
$portion[1]);
$cVal = ($cVal != 0)? $cVal : $portion[1];
$temp1 = $_POST['tfUnit'][$i] * $cVal;
$temp2 = $_POST['tfAmt'[$i] * 100;
$temp3 = $temp1 * $temp2;
$temp4 = $temp3 / 100;
$cpp += $temp4;
}
nik
Message #4 by peter@p... on Mon, 16 Sep 2002 23:19:10
|
|
Problem solved.
Forgot $cVal is an array,
so it should be $cVal[0]...DOH!!!
|
 |