Page 1 of 1
Trouble with maths
Posted: Tue Feb 28, 2006 11:59 am
by Ady
Okay, I'm trying to do this:
Code: Select all
$func1=$var1/$var2;
$func2=$var3-$func1;
So it divides $var1 by $var2, then it takes that away from $var3, but for some reason it sets the $fun2 variable as "-$func1"... so it doesn't subtract, it just sets the $func variable with "-(whatever the number of $func)". Is there an error in the code that makes this happen?
Any help would be appreciated.

Posted: Tue Feb 28, 2006 12:07 pm
by feyd
$var3 equates to zero.
Posted: Tue Feb 28, 2006 12:10 pm
by a94060
are you sure that the values are being passed on? that may be the problem why you are not getting the correct answer you may want to.
This code seems to be right,make sure the values passed are also numbers.
Code: Select all
$var1=$_POST['number1'];//replace number 1 with the name of the field you want as var1.
$var2=$_POST['number2'];//replace with the name of the field.
$var3=$_POST['number3'];
/*replace with the name of the field that will hold the number you want to be subtracted from.*/
$func1=$var1/$var2;
$func2=$var3-$func1;
the only thing i think that may be wrong in what i put is the firection of the slash(/)
Posted: Tue Feb 28, 2006 12:19 pm
by Burrito
why don't you try echoing out your $var's and see what they are to ensure you're dealing with what you think you're dealing with....
Posted: Tue Feb 28, 2006 12:22 pm
by a94060
burrito,your a genious haha

Posted: Tue Feb 28, 2006 12:54 pm
by Ady
Ah thanks for everyone's help, but I fixed the problem on my own. Thanks anyway.

Posted: Tue Feb 28, 2006 3:50 pm
by a94060
its always good when people find their own SOULUTION
