This topic is locked

calc

12/28/2008 10:37:10 AM
PHPRunner General questions
B
bobby123 authorDevClub member

Hi
Hope someone can help me with a problem I have .
I have a table which is used to calculate mileage per gallon, and to do this I need to take the last recorded mileage and divide it by the new ly endered mileage.
So I need to find a way of taking the value of the mileage Feild in the last record added and divide it by the new record on the add record action
Hope this make sence
thanks
Bobby

J
Jane 12/29/2008

Hi,
here is a sample:

global $dal;

$rs = $dal->TableName->Query("","RecordID DESC");

$data = db_fetch_array($rs);

echo $data["mileage"];

B
bobby123 authorDevClub member 12/30/2008

Hi,

here is a sample:


Thanks Jane, I put the code in the Before Add Record event, but it dosn't work. I think have not explained what I am trying to do very well.
I have a table called Fuel data with a field named Mls, when my user enters his Mileage inh the Field Mls Thanks Jane, I put the code in the Before Add Record event, but it doesn't work. I think have not explained what I am trying to do very well.
I have a table called Fuel data with a field named Mls, when my user adds a new record I would like to subtract the Mls field on the last saved record from the Mls field in the new record and then use that to calculate the MPG field.
Hope this explains my problem better Jane
Thanks for the help#
Bobby

J
Jane 1/5/2009

Hi,
just use code mentioned before: select value of last saved record and calculate new value:

global $dal;

$rs = $dal->TableName->Query("","RecordID DESC");

$data = db_fetch_array($rs); //

$values["MPG"] = $values["Mls"]-$data["Mls"];