Jump to content

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*
Link to comment
https://forums.phpfreaks.com/topic/24010-color-coat-identical-rows/
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.