brosskgm Posted February 14, 2010 Share Posted February 14, 2010 I have a small database that keeps track is miles for each day worked and the code was written for me. The mileage fields are all edit box fields. What I would like to do is to put a calculate button to to subtract the start miles from the end miles and put the result in total_miles_driven edit box. I've look at http://us.php.net/manual/en/function.array-sum.php But can't seem to grasp subtraction. I've tried ($mileage_stop - $mileage_start) = array('total_miles_driven'); But doesn't seem to work. Not understanding enough about calculations in php I'm at a loss. Thanks else if(SUBDIR == 'mileage') { $fields[] = array('name' => 'work_date', 'type' => 'date', 'len' => 15); $fields[] = array('name' => 'project', 'type' => 'varchar', 'len' => 50); $fields[] = array('name' => 'mileage_start', 'type' => 'varchar', 'len' => 15); $fields[] = array('name' => 'mileage_stop', 'type' => 'varchar', 'len' => 15); $fields[] = array('name' => 'total_miles_driven', 'type' => 'varchar', 'len' => 15); $fields[] = array('name' => 'notes', 'type' => 'text', 'len' => 100); // When this var is set, will enable date selection for the given fields $date_selection_fields = array('work_date'); $totals_fields = array('total_miles_driven'); Link to comment https://forums.phpfreaks.com/topic/192005-calculation-of-two-fields-with-results-in-another/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.