Generating Advanced Subheadings

From: Date: Thu, 11 Mar 2004 16:29:23 +0000
Subject: Generating Advanced Subheadings
Groups: php.general 
Request: Send a blank email to php-general+get-180186@lists.php.net to get a copy of this message
Can we take this one step further and make it so that if you're searching and you want to only see histories with the words "parking" in the title or only the histories between 1500 & 1550 it only puts the year headings for the years that actually have a history that meets this criteria? Thanks Nicole "Nicole" <ndirato@jenkinslaw.org> wrote in message news:20040219193419.53589.qmail@pb1.pair.com... > 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" <rich@launchcode.co.uk> wrote in message > news:1849384669.20040219191241@launchcode.co.uk... > > 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 "Nicole" <ndirato@jenkinslaw.org> wrote in message news:20040219182810.22290.qmail@pb1.pair.com... > 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: > ------------------------------------- > > <b>1915</b> > <p>(20, '1915', '192', '', '', '312', > '525', '404', '', 'title')<br> > (21, '1915', '338', '', '', '736', > '0', '929', '', 'title') > > <b>1917</b> > <p>(22, '1917', '193', '', '', '447', > '0', '1275', '', 'title') > > <b>1919</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 "<p><b>" . $years["year"] . "</b>"; > } > print "<p><a 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!

« previous php.general (#180186) next »