This topic is locked

Calculate

2/16/2023 5:29:09 PM
PHPRunner General questions
Roosevelt author

hello everyone, I need to calculate the difference between the number 2 and 1, Do not know how to do, can someone help me? I need to take the value from the previous day and decrease the day after
img alt
.

M
m3 2/16/2023

This is an interesting problem. I would approach it in one of either 2 ways (2 cents worth):

  1. On the List page, keep the amount into a PHP Session prior to moving to the next row. Then when you are at the next row, call back the Session variable and deduct. (This is not elagant but it should works)
  2. Do it inside the database (https://stackoverflow.com/questions/35456962/subtract-value-from-previous-row-in-mysql)

Roosevelt author 2/17/2023

Hello M3, tks for help.
May you show me how to do it using my fields? I don't know how to keep the amount into a PHP Session prior to moving to the next row. My programming level is very low, but I am hardworking and persistent.
I know I'm asking a lot, but can you build this code and post here?

C
cristi 2/18/2023

As m3 suggested php sessions would be one way to do it:

  1. in list page before process you create a session and assign 0 value to it: $_SESSION["diff"]=0;
  2. You change field type for "observacao" to custom and add the code below:

$_SESSION["diff"]=$data["Diario_aqua"]-$_SESSION["diff"];

if ($_SESSION["diff"]==$data["Diario_aqua"])
{
$value='';
}
else
{
$value=number_format((float)$_SESSION["diff"], 2, '.', '');
}

Adjust field names accordingly.... your language (it seems to be portuguese?) is not my native language so field names are not identical but you get the idea: it's a simple conditional where you create a session, assign a intial value, make a substraction and if the result is equal with the one from the column before you hide it by using an empty string otherwise you display the result - I don't know how you choose to format your floating point numbers so for the sake of demonstration I used "number_format" from PHP to format the result with two decimals - it is not mandatory - you use it if you need it....

End result:

img alt

Roosevelt author 2/18/2023

Wonderful ... thank you very much, how can I study programming in phprunner like you??? Where do I start, where do I find material specific to phprunner.
One more detail the STORE, in this case I have store1; store2; store3 and store5. I need the calculation to be done by store. Forgive me for being abusive.

Sergey Kornilov admin 2/18/2023

There is nothing PHPRunner specific in this code, just a basic understanding of how PHP works and what session variables are. Any basic PHP tutorial will work for you. Better yet, take the code provided and adopt it for other uses, learn by doing.

What can be helpful though is the understanding of what events are available in PHPRunner. This article can help:
https://xlinesoft.com/phprunner/docs/page_life_cycle_overview.htm