Jump to content

Adding field together


supanoob

Recommended Posts

It would add each individual field up, so in the case of the code he posted:
speed_amount = 9
power_amount = 9
dex_amount = 9

Now are you talking about adding the sum of each of those up as well? To get 27? If so, Im not sure how to do it by sql but you could then do this:

print($speed_amount + $power_amount + $dex_amount);
Link to comment
https://forums.phpfreaks.com/topic/16492-adding-field-together/#findComment-68863
Share on other sites

[code]
<?php
$query="SELECT SUM(speed) as speed_amount, SUM(power) as power_amount, SUM(dex) as dex_amount FROM table";
while($record=mysql_fetch_assoc($query)) {

$total_result=$record['speed_amount']+$record['power_amount']+$record['dex_amount'];

echo"Totlal for speed is: $record['speed_amount']<br>
Totlal for power is: $record['power_amount']<br>
Totlal for dex is: $record['dex_amount']<br>
Totlal is: $total_result<br>";
}
[/code]

Link to comment
https://forums.phpfreaks.com/topic/16492-adding-field-together/#findComment-68865
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.