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!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to