I'd be interested in someone looking over this foreach loop to see if there is a better way to do this. These loops gives me exactly what I need but I can't help but think it isn't the best practice or even the right way of doing it.
The $reports variable is an array that holds data from my db. An example of what may be in the array is:
Hopefully, you can see that I have 4 rows where the first 8 columns are all exactly the same with the exception of the person's name and date of birth. What I need is to use this array to build an html report. In my code sample below, the outer loop gets only the first row to build the first page then the inner loop iterates over the people's names and date of birth
Can someone please tell me if there is a better way of doing this?
The $reports variable is an array that holds data from my db. An example of what may be in the array is:
Code:
Report12 Title1 2 Administrator test note Deposit made 2009-05-03 04:01:22 1 Wilma Ventura 1970-06-04 Report12 Title1 2 Administrator test note Deposit made 2009-05-03 04:01:22 1 Jane Williams 1967-07-11 Report12 Title1 2 Administrator test note Deposit made 2009-05-03 04:01:22 1 Jack Williams 1969-04-19 Report12 Title1 2 Administrator test note Deposit made 2009-05-03 04:01:22 1 Bob Savana 1959-09-15
Can someone please tell me if there is a better way of doing this?
Code:
$oldarr = $reports; $newarr = array_splice($reports,0,1); foreach($newarr as $val) { // my first 8 columns will go here if($val['rpt_type'] == 'Report12') { foreach($oldarr as $rpt) { echo $rpt['fname'],$rpt['lname'],$rpt['dob'] . '<br>'; } } } }
Comment