This topic is locked
[SOLVED]

 help search field above

10/11/2011 4:30:25 PM
PHPRunner General questions
B
bilboss author

I have a big problem,

I have a table that registers the number of vehicle and current mileage.

what is that you NEED to register FOLLOWING same vehicle mileage take a field above, for example so
Vehicle Code / mileage current / previous mileage

cod01 / 100 / 0

cod01/245/100

cod01/360/245 .....
Thanking you

forgive my basic English

C
cgphp 10/11/2011

In the "Before record added" event, enter this code:

$rs = CustomQuery("SELECT MAX(id), mileage_current FROM mileage_table_name");

$record = db_fetch_array($rs);
$values['previous_mileage'] = $record['mileage_current'];


Change fields and table names according to your needs.

B
bilboss author 10/13/2011

thanks christian, but I do not work at all.
since the code returned it to me on more than one id,

and nose that do want to enter another vehicle code
example
Vehicle Code / mileage current / previous mileage

cod01 / 100 / 0

cod01/245/100

cod02/200/0

cod01/360/245

cod02/500/200 .....
thank you very much for helping

C
cgphp 10/13/2011

I'm not sure I understand what you want to do.

B
bilboss author 10/13/2011

I need to create a record for vehicle fuel efficiency, so NEED that each vehicle code will automatically add previous mileage when entering a new record, nose if I explained well, greetings

C
cgphp 10/13/2011

The code above should solve your issue. The query needs a WHERE clause to filter the records that match the new vehicle code you are adding:

$rs = CustomQuery("SELECT MAX(id), mileage_current_field_name FROM mileage_table_name WHERE vehicle_code_field_name='".$values['vehicle_code_field_name']."'");

$record = db_fetch_array($rs);
$values['previous_mileage_field_name'] = $record['mileage_current_field_name'];


Change fields and table names according to your needs.

B
bilboss author 10/14/2011

hello cristian code works for me, but returns the data from the first record of the vehicle code or not the last, and to provide with MIN(id) and neither worked, have any idea how to solve this problem,

thank you very much for everything

C
cgphp 10/15/2011

What are the fields names of the table ?

B
bilboss author 10/15/2011

id / vehicle_Cod / Mileage_previous / current_mileage /
these are the fields

thanks