This topic is locked
[SOLVED]

 sum of one field from all records

5/1/2012 6:21:35 PM
PHPRunner General questions
S
scoobysteve author

Hi guys I have a PHPR app that each record that is added a mileage amount is entered, is it possible to show the sum of all these miles added up when displaying any of the records that contain this field in another available field.
In other words if there was 15 entries each running in date order 01/01/2012 to 01/16/2012 that had a mileage value added to them, what ever of these records were opened in view mode would show the current amount of miles so far to that date.
Field value in each record equals (Miles) spare field available = (TotalMiles)
So when the view page is displayed you get that days miles shown in the (Miles) field and the total amount of miles so far to that date in the (TotalMiles) field
I hope this all makes sense
Is this possible
Kind Regards

Steve

C
cgphp 5/2/2012

Set the alias field (spare field) as Custom and enter a code like this:



$rs = CustomQuery("SELECT sum(Miles) AS total_miles FROM table_name WHERE date_field_name <= '".$data['date_field_name']."'");

$record = db_fetch_array($rs);
$value = $record['total_miles'];
S
scoobysteve author 5/3/2012



Set the alias field (spare field) as Custom and enter a code like this:



$rs = CustomQuery("SELECT sum(Miles) AS total_miles FROM table_name WHERE date_field_name <= '".$data['date_field_name']."'");

$record = db_fetch_array($rs);
$value = $record['total_miles'];



Thank you so much that worked fine. I am just trying to keep the whole application easy to use with certain values being automated and this was one of them, thanks again.

Steve