How to query db and sum the rows returned

Hello,

I have a need to query the DB for all products sold to a client then get the total. This then needs to be displayed in a field.

I am using SugarCRM CE 6.5.13

I would greatly appreciate any assistance.

Thanks.

Parents Reply
  • <?php

    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once('include/MVC/View/views/view.detail.php');

    class OpportunityViewDetail extends ViewDetail {

    funtion display(){

           global $db;

           $id =  $this->bean->id;

        $query = "SELECT count(id) AS total FROM op_ps_product_sales";

        $result = $db->query($query);

        $row = $db->fetchByAssoc($result);

        $totalSales = $row['total'];

        echo "

    <script>

              var total = '$totalSales';

              $(document).ready(function(){ 

              $('#total_sales_c').after(total);

      });

    </script>";

    parent::display();

    }

    }

    ?>

Children