Page 1 of 1

How do you subtract one Integer Variable from another?

Posted: Sat Aug 01, 2009 5:12 am
by Paradox187x
I want to subtract a number in the DOWNVOTES from the UPVOTES from a SQL table and show the answer.

I'm guessn' you can't perform arithmetic in HTML, the only option is JavaScript, unless you can do it in PHP while echoing a table of data.

This is my JavaScript attempt, but of course it doesn't work.

echo " <td><script type='text/javascript'>v=($row['UPVOTES'])-($row['DOWNVOTES']) document.write(v)</script></td>\n";

1) Can you perform arithmetic on 2 $row variables with PHP before echoing the result (instead of using JavaScript)?

2) IF NOT, how could I get the above code working?

Thanx

Re: How do you subtract one Integer Variable from another?

Posted: Sat Aug 01, 2009 5:30 am
by aceconcepts

Code: Select all

 
$v = $row['UPVOTES'] - $row['DOWNVOTES'];
 
echo $v;
 

Re: How do you subtract one Integer Variable from another?

Posted: Sat Aug 01, 2009 7:14 am
by Paradox187x
Thanx,

I don't know why I have to over complicate things :)