sum in collons and fields

A place for users and developers of the Xataface to discuss and receive support.

Postby neku » Tue Apr 17, 2007 5:21 am

hello dataface workers

i am brand-new here. i find dataface fantastic and want build one app thereby. but i find not all information which i need. for example:

a) how can i sum collons and display it in tablefooter (listfooter)?
b) how can i display this in detail-can someone help me?

is somewhere an example?

much thanks in advance

ps:
(my english is poor. but i hope, with a little help from aunt google, (much thanks steve) i am gona make it: http://translate.google.com/translate_t)
neku
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue Apr 17, 2007 9:16 am

Hi Nestor,

This is a bit tricky, but possible.Ê It involves a few concepts:

1. You can insert content after the list view using the block__after_result_list() method in the delegate class.

2. You can calculate whatever totals you want in that method.


For calculating your totals, you will probably need to know what the current query is that dataface is using.Ê You can build portions of the query using the Dataface_QueryBuilder class and passing the query array to it:

e.g.

function block__after_result_list(){
ÊÊÊ $app =& Dataface_Application::getInstance();
ÊÊÊ $query =& $app->getQuery();
ÊÊÊ $queryBuilder = new Dataface_QueryBuilder($query['-table'], $query);
ÊÊÊ $where = $queryBuilder->_where();Ê // the where clause
ÊÊÊ $from = $queryBuilder->_from();Ê // the from clause
ÊÊÊÊÊÊÊ
ÊÊÊ $sql = "select sum(income) as total_income, sum(expense) as total_expense $from $where";
ÊÊÊ $res = mysql_query($sql, df_db());
ÊÊÊ list($total_income, $total_expense) = msyql_fetch_row($res);
ÊÊÊ echo "

Totals:


ÊÊÊÊÊÊÊÊÊÊÊÊ

ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ
Income
$total_income

ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ
Expense
$total_expense

ÊÊÊÊÊÊÊÊÊÊÊÊ
";
}

This will make the total income and expense show up in the footer of list view. (Note I haven't tested this, so there may be bugs in this code.. but it is pretty much right.
-Steve





--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby neku » Wed Apr 18, 2007 2:20 am

hi steve

much thanks, i will try it in such a way.

neku
neku
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 3 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved