Jump to content

Subtraction in PHP


NoMansLand

Recommended Posts

Hello,

 

I am running this script:

 

while($row = mysql_fetch_array($query)) {
$compare_points_1 = $row['sideone_points'];
$compare_villages_1 = $row['sideone_villages'];
$compare_members_1 = $row['sideone_members'];	
$compare_points_2 = $row['sidetwo_points'];
$compare_villages_2 = $row['sidetwo_villages'];
$compare_members_2 = $row['sidetwo_members'];	
}
$point_1 = $_POST['points_1'];
$village_1 = $_POST['villages_1']; 
$member_1 = $_POST['members_1'];
$point_2 = $_POST['points_2'];
$village_2 = $_POST['villages_2']; 
$member_2 = $_POST['members_2'];

$points_1_calc = $compare_points_1 - $point_1;
$villages_1 = $compare_villages_1 - $village_1;
$members_1 = $compare_members_1 - $member_1;
$points_2 = $compare_points_2 - $point_2;
$villages_2 = $compare_villages_2 - $village_2;
$members_2 = $compare_members_2 - $member_2;

 

When I try to output $points_1_calc it gives me: -100

 

It will Add & Times & Divide but not Subtract.

 

Everything fills with Numbers only and I've tried this seperately and it works on a different script where I manually put in the numbers.

 

All variables fill with numbers as I have a part above that doesnt go through if there is nothing to compare against.

 

Any help would be greatly appreciated.

Link to comment
Share on other sites

Will there be situations where the while loop will execute more than once? If so, the calculations should probably be inside the loop. Otherwise things like "$points_1_calc = $compare_points_1 - $point_1;" will only be calculated based on the values pulled from the last time through the loop.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.