PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
sum of a column

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures
View previous topic :: View next topic  
Author Message
jurassicjeff



Joined: 03 Oct 2007
Posts: 16

PostPosted: Wed Oct 17, 2007 2:02 pm    Post subject: sum of a column Reply with quote

Hi, I am new as pear user and I would like to use structure datagrid to
display results of queries. (I am trying to work with db_table at the moment)
I have read different tutorials and I did not find answer to my question.

How can I display in the last row, results of som of a column.
Do I have to get result array of the query, calculate sum and recreate an array with a supplementary row with totals, or doest exist something easier.

How can I have different format (size , bold ) for displaying a special cell (like total).
thank you

Jeff
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1048

PostPosted: Wed Oct 17, 2007 6:15 pm    Post subject: Reply with quote

There is no code for this because there are some many different things that users could want to do with SDG. But it's still possible. After bind(), do the following steps:

Step 1: Get the HTML_Table object:
$table = $datagrid->getRenderer()->getContainer(); // on PHP 4, you have to split this line into two lines

Step 2: Get the table footer:
$footer = $table->getFooter();

Step 3: Calculate the value
$totalValue = $db_table_object->select('total'); // 'total' needs to be defined in $sql, e.g. as 'SUM(whatever)'

Step 4: Add the value, style the cell (maybe merge cells?)
$footer-setCellContents(0, 0, $totalValue);
$footer->setCellAttributes(0, 0, array('style' => 'font-weight: bold', 'colspan' => 5));

This is just one possible way. Another one would be to use $datagrid->fill() with your HTML_Table object (that would be filled by SDG).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software