I am generating a table dynamically. Each table has multiple columns
and various calculations need to be done on each column and displayed
at the bottom of the column. I am including the code from one table below.
The $tablerow generates the table data and the $tablefooter generates the
rows at the bottom that will include the calculated values. Preceding this,
I have declared some variables and done calculations. I then included these
in the $tablefooter to display the calculated values. This works fine.
However, I have many other calculations on other columns in other tables.
Using this method, I would have to declare many new variables just for calculations.
I am wondering if there is a more efficient way of doing these calculations.
I am new to PHP and calculations. I understand that 'sum' is typically done in
a query statement. Can calculations be done in the html, where I am displaying
the value of the variables?
$sumpop += $POP;
$sumadultcirc += $ADULTCIRC;
$sumjuvcirc += $JUVCIRC;
$tablerow[1] = "<tr><td>" . $row["name"] . "</td>" . "<td>$POP<td>$ADULTCIRC</td>
<td>$JUVCIRC</td><td>$TOTCIRC</td><td>$CIRCPERCAP</td><td>$TOTREF</td><td>$REFPERCAP</td></tr>";
$tablefooter[1] = "<tr><td><b>Table total</b></td><td><b>$sumpop</b></td>
<td><b>$sumadultcirc</b></td><td><b>$sumjuvcirc</b></td><td><b>$TOTCIRC</b></td>
<td><b>$CIRCPERCAP</b></td><td><b>$TOTREF</b></td><td><b>$refpercap</b></td></tr>
<tr><td><b>Table average or per capita</b></td><td><b>$POPAV</b></td>
<td><b>$ADCIRCAV</b></td><td><b>$JUDCIRCAV</b></td><td><b>$TOTCIRCAV</b></td>
<td><b>$CIRCPERAV</b><td><b>$TOTREFAV</b><td><b>$REPERAV</b></td></tr>";