Summarizing Data / Producing Leading Grand Totals pt. 2
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
In this lesson, our second part of working with leading grand totals, we're going to go ahead now and finish displaying the grand totals for our summary report. In the previous lesson we talked about the difference between leading totals and trailing totals and how you approach that in your PHP programming. So in this lesson we're going to go ahead and just head right up to our new row at the top of our report, which is going to have the grand totals for all the locations, all items contained within and categories and so forth. So what we're going to do is we're going to have to create this average, which has a total sum of all the different life remaining years and divides that into the count of all the entries and then we're going to sum our total values and our total depreciation. Now, because it's a leading grand total, it's going to have to all happen at the top when we're working with our arrays at the beginning. So let's go ahead then and open up our location asset list page in the 1309 folder and what we want to do now is we want to scroll up near the top where we have all our array work done because we're going to have to work with these values up here. Before we were working with our average years and we had to come up with the total average years for each locations. So we had to parse our array. To do that we created this total count, which is initialized for each location. Then we loop through and added the count of each category to create the total count for each location. What we want to do now is create a total count for all the categories for all locations so we need to create a variable which begins its scope. Then what we need to do is we need to have this total or sum all the different counts for the categories. So we're going to have, use the shortcut operator again to plus equal the count. Now when this is all said and done, we'll have a grand total count near the bottom that we can work with to get our average. The second thing that we need is we need a sum of all the different years remaining. Well, we know that for each location we have all the years remaining summed up inside of our array summary array location life remaining summary. So what we need to do is we need to aggregate these together so we end up with a total for all our different locations. Well, when we get down the side of our foreach loop, we see that we erased or replaced this value, which was a sum, to its true average value right here on this line because we needed it for this leading average for each location. So to work with this value before it becomes an average and while it's still a sum, we need to do a code above this line. So we're going to say that our variable, which will initialize up here, our grand life remaining summary is equal to null. Remaining summary is equal to our array location name summary. And we need to do a plus equal here so that we can aggregate. Now we have a new grand life remaining summary that will be available to us when we're done with this loop. So to create our new grand average, we simply take our grand life remaining summary and divide it by our grand total count. And now we should be able to work with this inside of our header output. Here we have our grand totals and right here we're going to say that the average is, going into PHP mode, echo the number format grand average. Let's go ahead then and refresh our web page. Open up the 1309 and click on location assets and here we say that we have our average as 20 years and that's the same as in FileMaker. Well, that was the hard one now. All we need to do is to aggregate the totals for each one of our summaries to get the grand totals. So we'll initialize some variables for them. The grand value summary and also the grand depreciation summary. And then we just need to use these variables inside here to aggregate them as well. This is going to be equal to the plus equal, because we're aggregating. The life remaining, the value summary and then our depreciation variable is going to be equal to the summary array location name depreciation summary. So you can see we're just working with the values that we have in our arrays but we're doing it up on top because that's where we have the values created and then we'll just output our variables down below inside of our header in the HTML. So we're going to echo the number format for our grand value summary and we'll put in some decimals for that one. Go out of PHP mode and then we'll just copy this code and do the same one for our depreciation. And let's refresh this in the browser and see our finished report. So for our leading grand totals, we have 2,628,467, exactly what we have in FileMaker. And 1,495,008 and because we rounded in PHP we're just a hair off a few cents. So this concludes our lesson on how to summarize data in your PHP application by gathering your records from FileMaker, building these awesome arrays and then how to go through those arrays to create your different leading and trailing grand totals and format everything else out into your HTML output so that you can make your web reports look exactly like they do in FileMaker.
Tutorial Information
| Course: | FileMaker 9 & PHP Foundations |
| Author: | Lance Hallberg |
| SKU: | 33786 |
| ISBN: | 1-933736-99-2 |
| Release Date: | 2007-08-22 |
| Duration: | 9.5 hrs / 107 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 