WordPress.org

Ready to get started?Download WordPress

Forums

Custom Tables
[Plugin: custom tables] Calculated Fields? (6 posts)

  1. Caps
    Blocked
    Posted 2 years ago #

    Can you define totals or averages? If so, how?

    http://wordpress.org/extend/plugins/custom-tables/

  2. Stefan M.
    Member
    Plugin Author

    Posted 2 years ago #

    should work with php

    [wctphp]echo {field1} + {field2};[/wctphp]

    Of corse, both field NEED to be set. if one field is not set, an error will occure.

    Otherwise make it secure like:

    [wctphp]$var1 = '{field1}';$var2 = '{field2}';$total = (integer)$var1 + (integer)$var2;echo $total;[/wctphp]

    This will save 2 fields in 2 variables, change it to an integer and then add them together.
    average:

    [wctphp]$var1 = '{field1}';$var2 = '{field2}';$average = ((integer)$var1 + (integer)$var2)/2;echo $average;[/wctphp]

    This is normal PHP Code.

    Regards
    Stefan

  3. Caps
    Blocked
    Posted 2 years ago #

    Nice, thank you Stefan.

    Caps

  4. Caps
    Blocked
    Posted 2 years ago #

    Say that I wanted a grand total for each line item, how would I achieve this? Total =

  5. Stefan M.
    Member
    Plugin Author

    Posted 2 years ago #

    with the code above, add this to the table setup in a field.

  6. Caps
    Blocked
    Posted 2 years ago #

    Will try that.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic