(sorry for my english)

How can I output calculated fields based on other real table fields?

For example: I have table "user_stats" with fields "uploaded" and "downloaded" and I want to output also a "ratio" calculated field (which will be = uploaded / downloaded).

I could use "Global: Custom text" field with it's patterns, but it doesn't support PHP code in itself...

Should I create special "views_field_hook" which will support PHP code or is there other better solution?

Will it be solved in 6.x - 3.x - version?

Thanx.

CommentFileSizeAuthor
#2 views_handler_field_php.inc_.zip2.16 KBliquixis

Comments

dawehner’s picture

as fast solution you can use theming of global: custom text, and get the values from the other fields.

liquixis’s picture

Category: support » feature
Status: Active » Needs review
StatusFileSize
new2.16 KB

I implemented own "views_handler_field": "views_handler_field_php"

P.S. There is a typo in my first post: not "views_field_hook", but "views_handler_field".

liquixis’s picture

Title: How can I output calculated fields based on other real table fields? » Output calculated (by PHP) field based on other fields.
pixelantegroup’s picture

Cool solution!

Would I be able to use this solution as a grouping field in a view?

I tried using the Global: Custom Text field, but it seems as if the value is not calculated at the time the grouping is performed, so it was a no go.

liquixis’s picture

Thanks.

Yes, you can use this solution as grouping field in a view (I tested it with "Style: Table" "Grouping field").

I tried to group with "Global: Custom Text", but as you said, it doesn't work...

P.S. I'll post updated version soon (with some improvements).

merlinofchaos’s picture

Status: Needs review » Closed (won't fix)

I don't think I want a PHP field in Views itself. I recommend turning this into a module. It should require minimal maintenance, I would think, and would make it available as an addon for people who need it but would not be there for people who do not. Just be very careful with permissions so you don't open security holes.

kvvnn’s picture

Please excuse my ignorance, but this adds an additional field to Views? What is it grouped under, and what is its name?

kvvnn’s picture

Anyone interested in having a PHP field in Views should use this module : www.drupal.org/project/views_customfield