Jump to content


Photo

color-coat identical rows


  • Please log in to reply
1 reply to this topic

#1 nick1

nick1
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 15 October 2006 - 06:05 PM

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*

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 15 October 2006 - 06:49 PM

<?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>";
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users