How do you subtract one Integer Variable from another?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Paradox187x
Forum Newbie
Posts: 7
Joined: Mon Jul 20, 2009 6:24 am

How do you subtract one Integer Variable from another?

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

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

Post by aceconcepts »

Code: Select all

 
$v = $row['UPVOTES'] - $row['DOWNVOTES'];
 
echo $v;
 
Paradox187x
Forum Newbie
Posts: 7
Joined: Mon Jul 20, 2009 6:24 am

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

Post by Paradox187x »

Thanx,

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