0

In my view file i am generating a table as following

<?php
foreach ($accounts as $row) {
  echo '<tr>';
  echo '<td>' . $row['id'] . '</td>';
  echo '<td>' . $row['total_online_sale'] . '</td>';
  echo '<td>' . $row['product_price'] . '</td>';
  echo '<td>' . $row['discount'] . '</td>';
}
?>

I want to generate sum values of those columns in a row surrounded by <tfoot> tag. I don't want to do this operations in model. how should I do it?

1 Answer 1

1

You can do so,sum up values in your loop and after loop print these values in <tfoot> tag

<?php
$total_online_sale= 0;
$product_price=0;
$discount =0;
foreach ($accounts as $row) {
$total_online_sale += $row['total_online_sale'];
$product_price +=$row['product_price'];
$discount +=$row['discount'];
  echo '<tr>';
  echo '<td>' . $row['id'] . '</td>';
  echo '<td>' . $row['total_online_sale'] . '</td>';
  echo '<td>' . $row['product_price'] . '</td>';
  echo '<td>' . $row['discount'] . '</td>';
  echo '</tr>';
}
echo '<tfoot>';
  echo '<tr>';
  echo '<td>&nbsp;</td>';
  echo '<td>' . $total_online_sale . '</td>'; //Grand sum for column total_online_sale 
  echo '<td>' . $product_price . '</td>'; //Grand sum for column product_price 
  echo '<td>' . $discount. '</td>'; //Grand sum for column discount
  echo '</tr>';
echo '</tfoot>';

?>
Sign up to request clarification or add additional context in comments.

2 Comments

If I enable pagination this shows only the paginated results sum only. I still don't want to do this operation in model, is it possible to show entire sum in paginated page?
@Alvi_1987 its better if you ask another question with all the concerns you have and also provide me the link of question so i ll try my best

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.