Table calculator
by David on Thursday 29th January, 2009 at 14:01 COMMENTS (0)
Phew, had a bit of a headache working on calculations based on table data.
For those who want to know how I dealt with the PHP coding for this, here is a basic description.
First sorted all table information into field data variable $cells[][]
Then calculated each cell individually starting from top left and working across and down.
ie in cell B3
!= H1 * 25.5 / 1000
Get that calculation from the cells;
$calc = $cells[2][3];
Split the calculation using;
$calcs = split(" ", $calc);
Now we have each part of the calculation in array variables $calcs
$calcs[1] contains "H1";
$calcs[2] contains "*";
etc.
First calculates H1 * 25.5
H1 is converted into the field location 8 x 1
So we can load that into our variable;
$a = cells[8][1];
So now $a contains the value of this particular item say 21000
So now calculate 21000 * 25.5 and get an answer;
$answer = $a * $b;
$a = $answer;
We loop until all the calculations are used up;
$a now contains 535500
$b gets the next calculation from $calc[] which is 1000
$answer = $a / $b
$answer is 535.5
Store answer in the cells.
$cells[2][3] = $answer;
Thats about it.
All working.
No Comments posted yet
