• Resolved erwant

    (@erwant)


    Hello,

    I display a value in B1 cell using php code like this :
    <?php global $nbrepersonnes; echo $nbrepersonnes; ?>
    where nombrepersonnes is equal to 4 for example.

    I can display it but when I use it in D1 for example I get the following comment in D1 (D1 = B1 * 4)
    !ERROR! B1 does not contain a number or expression

    How is it possible to use a value from a php code in other cells ?

    Thank you

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    The problem here is that the formulas are evaluated before the PHP code. Thus, the formula sees the code and not the number. To achieve that, you would have to modify the filter hook in the PHP in Tables Extension, so that it e.g. runs on the array values of the tablepress_table_raw_render_data hook, defined here: https://github.com/TobiasBg/TablePress/blob/master/classes/class-render.php#L119

    Regards,
    Tobias

    Thread Starter erwant

    (@erwant)

    Hi thank you ,

    could you just help me to understand where are the PHP table extension.

    Thank you

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    the Extension that you are already using to display a value: https://tablepress.org/extensions/php-in-tables/

    Regards,
    Tobias

    Thread Starter erwant

    (@erwant)

    Hi Tobias, I tried tout solution but can’t find the way to make it work.
    Could you please help me a little bit more ?

    Thank you very much

    Erwan

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    unfortunately, I’m very busy and don’t have the time to develop the full solution for you.
    If you check the source code of the PHP in Tables Extension, you will see that it runs on every cell via the tablepress_cell_content filter hook.

    You should change that, so that it runs on every cells of the $table['data'] array that you get when instead hooking into the tablepress_table_raw_render_data filter hook.

    Regards,
    Tobias

    Thread Starter erwant

    (@erwant)

    Thank you Tobias,

    This is what I did, but it doesn’t work. 🙁
    I replaced tablepress_cell_content by tablepress_table_raw_render_data in TablePress Extension file: tablepress-PHP-in-tables.php
    I understand that this will execute php in table extension when $this->table = apply_filters( ‘tablepress_table_raw_render_data’, $this->table, $this->render_options ); is called but when I do that, save table in backend office and then update my website page it doesn’t display anything.

    The fact is this feature is really important for me, I am blocked in finding a solution for what I want to do. I understand that you are very busy in pluggin development, but could I have your help so I can go ahead on my project.

    Thank you very much

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    just changing that filter is not sufficient. The tablepress_table_raw_render_data hook gives you an array, while tablepress_cell_content gives you a string. You will need to add an intermediate function that loops through the array cells and call the original function on those.

    Regards,
    Tobias

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Use value from php’ is closed to new replies.