Greetings friends!
I’d like to preface this by saying I’m quite new to php, but I’ve come to love it so far. I’ve never worked with php or html (or javascript, really) until a month ago, and I’m really interested in advancing my knowledge of the subject.
So, my question: I need to calculate miles per gallon given two entries from a table.
I have a table named fuelups with columns that contain an entry for odometer reading and the amount of fuel added to a vehicle. Specifically, it would be fuelups.odometer and fuelups.gallons
What needs to happen is:
-
Nothing if there is only 1 record [as it requires two points to generate a number]
-
If 2+ records are found, pull the recent two (they are date/timestamped by fuelups.date and are assigned to a user id fuelups.UID) and perform the mpg calculation and store it in the most recent record.
I’ve not much clue about how to do calculations across two records, so a general concept works and then we can perhaps get into specific code?
Thank you in advance for your assistance!