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

Post a comment

Comment Guidelines:
Please provide valid email address.
Email addresses are never displayed. HTML is not permitted. Line breaks and paragraphs are automatically generated. Off-topic or inappropriate comments will be edited or deleted. Email addresses will never be published but may be added to our mailing list.
Thanks.

Name: (required)

E-Mail: (required, never displayed)

URL: optional

Comments:

Receive email when someone replies.
Subscribe to this blog by email.

 

To prove you're a person (not a spam script), type the security text shown in the image.

 

Blog . Login

 

Most Recent Posts

5 Most Recent Posts

Most Recent comments

5 most recent comments

Subscribe by Email


 


Categories


Archives

My Flickr stream

www.flickr.com
DrAdept's Favourites photoset DrAdept's Favourites photoset

RSS Feed XHTML CSS 508

[Valid RSS]


 

Dr Adept web design & SEO consultants based in Basildon Essex.