funkyz0r funkyz0r - 5 months ago 17
PHP Question

Difference between two query

I have a question, it is possible to difference (mathematic operation) between two results?

Here is the code:

<?php
$row = $query->row();
echo "<b>Your total expenses:</b><br />". $row->TotalExpense;
?>

<?php
$row = $query2->row();
echo "<b>Your total incomes:</b><br />". $row->TotalIncome;
?>


Can I make something like:
TotalIncome - TotalExpense?

<?php
$x = query2
$y = query1

echo $x - $y;
?>


Thanks!

Answer

If your start point is right. You kind of already had it.

<?php 
$TotalExpense = $query->row()->TotalExpense;
$TotalIncome = $query2->row()->TotalIncome;

echo "<b>Your Balance:</b><br />". ($TotalIncome - $TotalExpense);
 ?>
Comments