I am trying to figure out how to parse an associative array I have constructed from database data in such a way that I can produce the html table layout that I’m looking for.
Associative array structure is as follows:
Array
(
[2013] => Array
(
[1] => Array
(
[Total] => Array
(
[validleads] => 7327
[conversions] => 9856
[bookings] => 2449
)
... more types for this week
[PPC] => Array
(
[validleads] => 884
[conversions] => 1109
[bookings] => 605
)
)
.. more weeks for 2013
)
[2012] => Array
(
[1] => Array
(
[Total] => Array
(
[validleads] => 9423
[conversions] => 12459
[bookings] => 2629
)
[PPC] => Array
(
[validleads] => 955
[conversions] => 1237
[bookings] => 601
)
)
)
So, there is one global array ($data) which contains an array for each year and in the arrays for each year there is an array for each week of the year which in turn has an array of figures for that week plus a totals array.
Table structure ideally would be
| Week | Total 2013 | Total 2012 | PPC 2013 | % PPC 2013 | PPC 2012 | % PPC 2012 | Other types 2013 | % Other types 2013 | Other types 2012 | % Other types 2012
| 01 | 7327 | 9423 | 884 | 12.06% | 955 | 10.13% | | | |
The percentages are just worked out by taking the figure for the that week in the year and dividing it by the total for that week of the year multiplied by 100.
The table layout I want to produce is to generate one table row per week of the year with the total for that week in each year aswell as the total for each type in that week each year and the percentage this total is for the overall total of the week for that year….
Sorry if that’s complicated….
Problem is I just can’t think how to produce what I want in HTML table format.
I know some foreach‘s are required but that’s as far as I get to.
Something like this you’d need a little work basically you’ll have to lay out your table a little differently for it to work/look right but should be doable. Code below isn’t perfect but hopefully will help you get your head around the problem.