⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

I need to sum rows and columns like in a spreadsheet



rhalsey
  • profile picture
  • Member

Posted 08 November 2011 - 11:39 AM

Hello!!

This is GREAT stuff!! I had almost given up on codeigniter when I found your script!

I am using version 1.1.3.

I need to sum rows and columns.

Can you tell me how to do that?

[u]__[b]_Item_[/b]____[b]J[/b]___[b]F[/b]___[b]M[/b]_ [b]Tot [/b][/u]
[u][b]Good Days[/b] | 10 | 20 | 30 | 60 |[/u]
[u][b] Bad Days[/b] | 20 | 30 | 40 | 90 |[/u]
[u][b]Total Days[/b] | 30 | 50 | 70 | 150 |[/u]

Any help you could give would be great!!

Thank you again for your GREAT work!!!!!!!

Rich Halsey
www.marricorp.com

rhalsey
  • profile picture
  • Member

Posted 10 November 2011 - 00:22 AM

Can anyone help with this or at least point me in the right direction?

Thanks in advance!!

goFrendiAsgard
  • profile picture
  • Member

Posted 11 November 2011 - 02:06 AM

Hi there, I think it is not about groceryCRUD, but it is about SQL.
Assume that you have 2 rows in your table_day(Item, J, F, M).

To make total row, you might need to make such a view (let's assume it as view_a) :

SELECT item, J, F, M, (J+F+M) as total FROM table_day

For total column, it might be more complicated.
You should make another view (let's assume it as view_b ):
SELECT 'total', sum(J) as J, sum(F) as F, sum(total) as total FROM view_a;


And you should make the third view that combine view_a and view_b (I forgot the detail, but you might googling for that).

I hope it can help.

Ah, there is some side effect of this, you should not edit, add, or delete from a view, that's mean that the grid can only be viewed (or you will need some complicated callback).

goFrendiAsgard

rhalsey
  • profile picture
  • Member

Posted 11 November 2011 - 10:23 AM

Thank you! It gives me a place to start!