Re: [HTML_DataObject_Browse] Calculate sum Fields
| From: | Justin Patrin | Date: | Wed, 23 Jun 2004 16:58:26 +0000 |
| Subject: | Re: [HTML_DataObject_Browse] Calculate sum Fields | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13275@lists.php.net to get a copy of this message | ||
Please don't hijack threads. Always create a new message instead of replying unless you're actually replying. If you don't, it includes your thread within another.
Nohuman wrote:
Hi! This is my hack to calculating sum(filed)'s in HTML_DataObject_Browse: First, create new $options value in descend class $options['sumRows'] = Array('importe','pagado'); //Numeric field's Second, hack HTML/DataObject/Browse.php the function BuildTotal function buildTotal() {-- paperCrane <Justin Patrin>$count = $this->_object->__clone(); $count->find(); $this->N = $count->count();// NEW CODE ****************************** if(count( $this->options['sumRows'])>0){ $sumquery = $this->_object->__clone(); $sumquery->selectAdd(); foreach ($this->options['sumRows'] as $dat ){ $sumquery->selectAdd("sum($dat) as sum$dat"); } $sumquery->find(true); foreach ($this->options['sumRows'] as $dat ){ $this->{'sum_'.$dat} = $sumquery->{sum.$dat}; } }// END NEW CODE ***************************}In this sample, 2 news object var are created: $this->sum_imprte and $this->sum_pagado, you can call this at Flexy_Template usually.... {sum_importe} .... Have fun!