This topic is locked

Calculating estimated mileage

10/13/2006 12:28:50 PM
PHPRunner General questions
W
wrpenman3 author

I am trying to figure out if there is a possible way to have the database auto update estimated mileage based on the average mileage driven monthly.
I have a field that asks what is the average mileage driven monthly per vehicle and in a second table I have the estimated mileage.
I would like to have the estimated mileage incremented by the averaged monthly mileage every month. Is there a way to do this?

T
thesofa 10/13/2006

From the maths side of things, you need to calculate the sum of all the mileage done and divide by the number of vehicles and the number of months.

This will give the average monthly mileage and wcan be shown as such on the page.
You say> I have a field that asks what is the average mileage driven monthly per vehicle and in a second table I have the estimated mileage.



Does this actually ask for the mileage for each vehicle?

If so, add the new mileage to the old total mileage figure and then use the same maths to calculate the new average mileage.

Adding averages to averages can lead to very disparate results.

HTH

J
Jane 10/16/2006

Hi,
generally PHPRunner isn't intended for periodically actions (every week, every month etc).
There is a workaround:

if you have a page visited often you can put your script which updates data every month to the ...onLoad event of this page.

Also you need to save the date of last execution of this script, calc the amount of time passed from the last execution date and run the script if needed.