views:

36

answers:

2

i have this function that takes two values and displays them, but its not doing the calculation right?

php code:

formatVote($votes_up,$votes_down)

$net_vote = $votes_up - $votes_down;

return <<<ENDOFRETURN
    <strong>$net_vote</strong>
ENDOFRETURN;

html page:

<?php
//rows retrieved from database....

formatVote($row['votes_up'],$row['votes_down']);
?>

p.s. i know the thier so no error from the mysql side of things,so the app is not calculating the results properly!

A: 

Have you tried to parse the variable like floatval($row['votes_up'])? You can also do the calculations straight from MySQL instead of creating such function.

http://dev.mysql.com/doc/refman/5.1/en/arithmetic-functions.html#operator_plus

Woppi
A: 

ok before we get an aswer i first need to you to do some testing for me and for yourself. in the code

formatVote($votes_up,$votes_down)

$net_vote = $votes_up - $votes_down;

return <<<ENDOFRETURN
    <strong>$net_vote</strong>
ENDOFRETURN;

please add

echo $votes_up + ' ' + $votes_down;

in the formatVote to find out what the values are.

This will be a changing post which will eventually be a correct answer as long as you keep up to date with me so we can solve this together

PK

Pavan