New Row for each Year?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron J
    New Member
    • Feb 2012
    • 2

    New Row for each Year?

    I have a database with records assigned to a year (2011, 2010, 2009, etc...)
    Each year may have up to three records assigned to it.
    How can I display a table to put each year on its own line (row)?

    SO for 2011, display the three records
    New row
    2010, display the three records, etc...

    Any help would be appreciated.

    Thank you!
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Don't write a break or similar HTML element to the document until there's a change in the year field.

    Comment

    • Aaron J
      New Member
      • Feb 2012
      • 2

      #3
      Thanks Rabbit-
      I guess my question is, how do I determine when it changes year?

      CODE:
      Code:
      $query = "SELECT * FROM tblProductionsMaster where ProductionYear < Year(now()) AND ProductionActive = 1 ORDER BY ProductionYear DESC";
      $result=@mysql_query($query);
      if ($result) {
      	echo '<tr>
      			<td style=\"padding-left: 10px;\">
      				<table border=0 width="100%" bgcolor=#ffffff>';
      $columnNum = 0;
      while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
      if($columnNum == 0)  {
      echo "<tr>\n";
      } 
      echo "<td valign=bottom align=center>
      		<table width=266 border=0 bgcolor=#ffffff>
      			<tr>
      				<td align=center><a href=\"production_detail.php?pid=$row[ProductionID]\"><img src=images/logos/$row[ProductionLogoSmall] border=0></a></td>
      			</tr>
      			<tr>
      				<td class=PastSeasonsGrid align=center><b>$row[ProductionName]</b></td>
      			</tr>
      			<tr>
      				<td class=PastSeasonsGrid align=center>$row[ProductionYear]</td>
      			</tr>
      			<tr><td><br></td></tr>
      		</table>
      		</td>\n";
      if($columnNum == 2) {
      echo "</tr>\n";
      $columnNum = 0;
      }
      else
      $columnNum++;
      }}

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Just store the year in a variable, when you read a new record, check if the year is different. If it is, write a break, and store the new year.

        Comment

        Working...