Michal, I tried to setup a virtual field which would keep totalling the Amount field in each row as follows:
Kód: |
$opts['fdd']['Balance'] = array(
'name' => 'Balance',
'select' => 'N',
'maxlen' => 14,
'sql' => 'SUM(Amount)',
'sort' => false
);
|
Unfortunately PME does not like this structure. Balance is expected to be a virtual field as it does not exist in the table.
the ideal sql statement for me would be :
Kód: |
'sql' => 'Balance + Amount' |
'Amount' is defined as a field in the table. Any ideas?
|
vistep Napísal: |
Dear all!
What is current status of implementation
"column total features"?
(not worked lines 2294-2336 in phpmyedit 5.5 v.1.167)
|
Dear all!
I implemented column total feature.
Code must be put on lines 2303-2345 phpmyedit 5.5 v.1.181
-------------------------
/*
* Display and accumulate column aggregation info, do totalling query
* XXX this feature does not work yet!!!
*/
if ($this->display['total'] && (((intval($this->fm / $this->inc) + 1)==( max(1, ceil($total_recs / abs($this->inc))))) or ($this->inc<0))) {
$qp = array();
$qp['type'] = 'select';
$qp['select']='';
for ($k=0;$k<$this->num_fds;$k++) {
$fd = $this->fds[$k];
if (isset($this->fdd[$fd]['total'])) {
if ($qp['select']!='') {
$qp['select'].=',';
}
if (isset($this->fdd[$fd]['sql'])) {
$qp['select'].= $this->fdd[$fd]['total'].'(PMEtable0.'.$this->fdd[$fd]['sql'].') as tot_'.$k;
} else {
$qp['select'].= $this->fdd[$fd]['total'].'(PMEtable0.'.$this->fds[$k].') as tot_'.$k;
}
}
}
if ($qp['select']!='') {
$qp['from'] = $this->get_SQL_join_clause();
$qp['where'] = $this->get_SQL_where_from_query_opts();
// $qp['limit'] = $this->fm.','.$this->inc;
$tot_query = $this->get_SQL_query($qp);
// print 'tc='.$tot_query;
$totals_result = $this->myquery($tot_query,__LINE__);
$tot_row = mysql_fetch_array($totals_result, MYSQL_ASSOC);
}
echo "\n",'<tr class="pme-row-total">',"\n",'<td colspan='.$sys_col_count.'class="pme-total">'.$this->total_label.'</td>',"\n";
// display the results
for ($k=0;$k<$this->num_fds;$k++) {
$fd = $this->fds[$k];
if (stristr($this->fdd[$fd]['options'],'L') or !isset($this->fdd[$fd]['options'])) {
echo '<td class="pme-cell-total">';
if (isset($this->fdd[$fd]['total'])) {
print $tot_row['tot_'.$k];
} else {
echo ' ';
}
echo '</td>',"\n";
}
}
echo '</tr>',"\n";
}
------------------------
After line 3077 phpmyedit 5.5 v.1.181
insert next code
-------------------------
$this->total_label = isset($opts['total_label'])
? @$opts['total_label']:'Total';
$this->display['total'] = @$opts['display']['total'];
-------------------------
Also need add sys_col_count var after line 2188
$sys_col_count=0;
and after line 2207
$sys_col_count++;
and after line 2271
$sys_col_count++;
and after line 2282
$sys_col_count++;
-------------------------------------------
Configuration.
1.Set display option TOTAL to true.
ex.
$opts['display'] = array(
'query' => false,
'sort' => true,
'time' => true,
'tabs' => true,
'total' => true
)
2. Add language depended total line
name
$opts['total_label']='Total line'
3. For field definition add
option TOTAL with function name (sum, count, etc...)
ex.
$opts['fdd']['Number'] = array(
'name' => 'Number',
'maxlen' => 11,
'default' => '0',
'total' =>sum
);
$opts['fdd']['DIFF_REAL_V'] = array(
'name' => '',
'options' => 'LF',
'select' => 'N',
'maxlen' => 10,
'sort' => true,
'sql' =>'DIFF-BONUS_USE',
'total' =>avg
);
Source code add at:
http://opensource.platon.sk/projects/bug_view_advanced_page.php?f_bug_id=399
|