Re: Generating Sub Headings

From: Date: Thu, 19 Feb 2004 19:08:29 +0000
Subject: Re: Generating Sub Headings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-178286@lists.php.net to get a copy of this message
Sorry about all of the code. I do do what you say to do there. My year sub headings are changing correctly, it's the data that's printed under each heading that isn't correct. Nicole "Chris W. Parker" <cparker@swatgear.com> wrote in message news:001BD19C96E6E64E8750D72C2EA0ECEE4478F0@ati-ex-01.ati.local... Nicole <mailto:ndirato@jenkinslaw.org> on Thursday, February 19, 2004 10:28 AM said: > I have data that looks like this: [snip] > The second value is the year, I have have multiple files for the same > year. What I want to do is output the values under Year sub headings. ok woh. that's way too much code for me to wade through so i'll just give you some ideas. hopefully you're not already implementing it. 1. you want to put your data in order (either ascending or descending) but the year. and according to your short data snippet it looks like you're already doing this. good job. 2. you need to somehow compare the date that's currently ready to be printed with what was ALREADY printed. the way you do this is by having a temporary variable that stores the previous year data. when the next loop cycle occurs you can say "is this current date the same as the previous cycles date?" and then act appropriately. for (...) { $current_date = $new_date; // if the current date does not equal the // old date you're obviously moving into // a new year and you should therefore // start a new group. if ($current_date != $old_date) { echo "<br/><br/>1915<br/>\n"; } else { echo "&nbsp;&nbsp;(20, '1915', ...)<br/>\n"; } $old_date = $current_date; } but of course instead of hard coding what gets printed you'd use your variables to print the correct values. hth, chris.

« previous php.general (#178286) next »