Jump to content

Archived

This topic is now archived and is closed to further replies.

nick1

color-coat identical rows

Recommended Posts

Greetings,

Lets say we have a MySQL table called Warranty.  The table could look something like this:

+---------+---------------+-------------+-----------+
| serial# |  description  |  startdate  |  enddate  |
+---------+---------------+-------------+-----------+
| 1234    |  blahblahblah |  2000.1.1  | 2000.12.30|
+---------+---------------+-------------+-----------+
| 1234    |  uh huh yeah  |  2001.1.1  | 2001.12.30|
+---------+---------------+-------------+-----------+
| 5678    |  something    |  2006.1.1  | 2006.12.30|
+---------+---------------+-------------+-----------+
| 5678    |  some more    |  2007.1.1  | 2007.12.30|
+---------+---------------+-------------+-----------+

As the table shows, it is possible for one serial# to have multiple warranties, this is fine.
Now lets say we want to display all of the information in the warranty table to the web browser.
Doing so is quite easy via the standard methods. 
However, to make things easier on the users eyes,
it would be helpful if each group of identical serial#'s were colored-coated with the same background color.
For example, all serial#'s which are "1234" would have a background color of gray.  The next group
of serial#'s would have a background color of white.  The next group of serial#'s would have a
background color of gray.  And so on and so forth, alternating between gray and white backgrounds.

It is easy to make every other row gray, but I am having a difficult time figuring out how to make
the background color of identical serial#'s the same.  Any input would be greatly appreciated.

Thank you for your time,

*Nick*

Share this post


Link to post
Share on other sites
[code]
<?php
  echo "<table>";
  while ($list = mysql_fetch_array($result)) {
      if ($list['serial#'] != $prev_row) {
        $color = ($color == '#AAAAAA') ? '#FFFFFF': '#AAAAAA';
      }
      echo "<tr><td bgcolor = '$color'>";
      echo "{$list['serial#']} {$list['description']}";
      echo "</td></tr>";
      $prev_row = $list['serial#'];
  }
  echo "</table>";
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.