No. of rows returned and sum of row field

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 29, 2014   (RSS)

By Chris - April 29, 2014

Hi zaba,

You can count the $basketRecords array with count():

There were <?php echo count($basketRecords); ?> record(s) returned.

The simplest way to sum a field is to use a variable and a foreach loop:

<?php
$sum = 0;
foreach ($basketRecords as $record) {
  $sum = $sum + $record['price'];
}
?>
The total price is: <?php echo $sum ?>

Does that help?

All the best,
Chris

By zaba - April 29, 2014

Just put it in and tested. Marvellous!

Thank you very much!