[PHP] Generating Sub Headings
I have data that looks like this: (20, '1915', '192', '', '', '312', '525', '404', '', 'title') (21, '1915', '338', '', '', '736', '0', '929', '', 'title') (22, '1917', '193', '', '', '447', '0', '1275', '', 'title') (23, '1919', '129', '', '', '208', '636', '0', '', 'title') (24, '1919', '274', '', '', '581', '321', '1634', '', 'title') 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. So it prints like this: - b1915/b p(20, '1915', '192', '', '', '312', '525', '404', '', 'title')br (21, '1915', '338', '', '', '736', '0', '929', '', 'title') b1917/b p(22, '1917', '193', '', '', '447', '0', '1275', '', 'title') b1919/b p(23, '1919', '129', '', '', '208', '636', '0', '', 'title')br (24, '1919', '274', '', '', '581', '321', '1634', '', 'title') - I have a function that displays each history in a loop. Here's the function: - function display_history($dbArray,$yearArray) { while($field = mysql_fetch_array($dbArray)) { $yeartitle=; while($years = mysql_fetch_array($yearArray)) { if ( $years[year] != $yeartitle) { print pb . $years[year] . /b; } print pa href=\ . $field[filename] . \ . $field[year]; //print the Resolution or Act Number if (!$field[res_no] !$field[j_res_no]) { print - Act # . $field[act_no]; } elseif (!$field[act_no] !$field[j_res_no]) { print - Res # . $field[res_no]; } else { print - J.Res.# . $field[j_res_no]; } //print the Public Law Number if ($field[pl_no]!=0) { print , P.L. . $field[pl_no]; } //print the Senate Bill Number if ($field[sb_no]!=0) { print , SB . $field[sb_no]; } //print the House Bill Number if ($field[hb_no]!=0) { print , HB . $field[hb_no]; } //close the link print /a - ; //print the Misc Text or Part Number if there is one if ($field[misc_part_no] != ) { print $field[misc_part_no] . - ; } //print the title and number of pages print $field[title] . - [ . $field[pgs] . pgs - ; //print the file size if ($field[mb] != 0) { print $field[mb] . mb]; } else { print $field[kb] . kb] ; } $yeartitle = $years[year]; } } } - The values being passed in are: - //get all of the histories from the table sorted by year //then resolution number then by act number $result = mysql_query(SELECT * FROM table ORDER BY year, res_no, j_res_no, act_no, misc_part_no,$connect); //get the years from the same table $yrArray = mysql_query(SELECT * FROM table ORDER BY year,$connect); //display histories display_history($result,$yrArray); - I'm sure it's an easy solution ... but here's what a resulting page looks like: - 1501 1501 - Act # 90, P.L. 647, SB 582 - this test - [5 pgs - 55kb] 1913 1501 - Act # 90, P.L. 647, SB 582 - this test - [5 pgs - 55kb] 1501 - Act # 90, P.L. 647, SB 582 - this test - [5 pgs - 55kb] 1501 - Act # 90, P.L. 647, SB 582 - this test - [5 pgs - 55kb] 1501 - Act # 90, P.L. 647, SB 582 - this test - [5 pgs - 55kb] 1925 1501 - Act # 90, P.L. 647, SB 582 - this test - [5 pgs - 55kb] 1501 - Act # 90, P.L. 647, SB 582 - this test - [5 pgs - 55kb] - And so on, always putting the right years and the right number of histories below the year, but always listing the first history and nothing else. My loop works if I don't have the while loop in there with the subheadings ... Thank in advance for any help you can offer! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Generating Sub Headings
Nicole mailto:[EMAIL PROTECTED] 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/1915br/\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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating Sub Headings
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 [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Nicole mailto:[EMAIL PROTECTED] 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/1915br/\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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating Sub Headings
Hello Nicole, Thursday, February 19, 2004, 6:28:13 PM, you wrote: N And so on, always putting the right years and the right number of histories N below the year, but always listing the first history and nothing else. My N loop works if I don't have the while loop in there with the subheadings ... In looking quickly at the code, I can't see a chance for the $field value to ever be updated. You call it once (in the first while statement) and populate the field array with the SQL results, you then move into the 2nd while loop which handles the years. But once in that loop you don't fill the $field array with any new data, so it's using the same data over and over again for every year. I believe, although I've not looked at it for very long, it's simply that the while loops are nested in such a way that the field values never get a chance to re-populate themselves. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating Sub Headings
That's exactly it! I don't know why I didn't think about that. For anyone else reading this, I added $field = mysql_fetch_array($dbArray); above the line that reads $yeartitle = $years[year]; And now it works! Richard Davey [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello Nicole, Thursday, February 19, 2004, 6:28:13 PM, you wrote: N And so on, always putting the right years and the right number of histories N below the year, but always listing the first history and nothing else. My N loop works if I don't have the while loop in there with the subheadings ... In looking quickly at the code, I can't see a chance for the $field value to ever be updated. You call it once (in the first while statement) and populate the field array with the SQL results, you then move into the 2nd while loop which handles the years. But once in that loop you don't fill the $field array with any new data, so it's using the same data over and over again for every year. I believe, although I've not looked at it for very long, it's simply that the while loops are nested in such a way that the field values never get a chance to re-populate themselves. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php