By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

New Row for each Year?

P: 2
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!
Feb 16 '12 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,366
Don't write a break or similar HTML element to the document until there's a change in the year field.
Feb 16 '12 #2

P: 2
Thanks Rabbit-
I guess my question is, how do I determine when it changes year?

CODE:
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT * FROM tblProductionsMaster where ProductionYear < Year(now()) AND ProductionActive = 1 ORDER BY ProductionYear DESC";
  2. $result=@mysql_query($query);
  3. if ($result) {
  4.     echo '<tr>
  5.             <td style=\"padding-left: 10px;\">
  6.                 <table border=0 width="100%" bgcolor=#ffffff>';
  7. $columnNum = 0;
  8. while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
  9. if($columnNum == 0)  {
  10. echo "<tr>\n";
  11. echo "<td valign=bottom align=center>
  12.         <table width=266 border=0 bgcolor=#ffffff>
  13.             <tr>
  14.                 <td align=center><a href=\"production_detail.php?pid=$row[ProductionID]\"><img src=images/logos/$row[ProductionLogoSmall] border=0></a></td>
  15.             </tr>
  16.             <tr>
  17.                 <td class=PastSeasonsGrid align=center><b>$row[ProductionName]</b></td>
  18.             </tr>
  19.             <tr>
  20.                 <td class=PastSeasonsGrid align=center>$row[ProductionYear]</td>
  21.             </tr>
  22.             <tr><td><br></td></tr>
  23.         </table>
  24.         </td>\n";
  25. if($columnNum == 2) {
  26. echo "</tr>\n";
  27. $columnNum = 0;
  28. }
  29. else
  30. $columnNum++;
  31. }}
  32.  
Feb 16 '12 #3

Rabbit
Expert Mod 10K+
P: 12,366
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.
Feb 16 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.