从Postgresql计算PHP查询

I made a succes table in php by postgresql query like this

<thead>
<tr>
<tr><th> no</th>
<th> package name</th>
<th> source </th></th>
<th> subject </th>
<th> price </th> =====> **currency**
<th> offer </th> =====> **currency**
<th> difference </th>
<th> category </th></tr>
</thead>
<tbody>
<?php

$count = 1;
while ($row = pg_fetch_assoc($result))
{
print "<tr>";
print "<td>".$count."</td>";
print "<td>".$row['pkg_name']."</td>";
print "<td>".$row['src_name']."</td>";
print "<td>".$row['sbj_name']."</td>";
print "<td><div align='right'>".$row['price']."</td>"; **=====>numb format 0.00**
print "<td><div align='right'>".$row['offer']."</td>"; **=====>numb format 0.00**
print "<td>".$row['diff']."</td>"; ===> reduce ['price'] by ['offer']
print "<td>".$row['category']."</td>";
print "</tr>";
//other code
$count=$count+1;
 }

How to reduce price by offer column, and create last row as sum total by price, offer, and difference column. Thanks

</div>