nick1 Posted October 15, 2006 Share Posted October 15, 2006 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 groupof serial#'s would have a background color of white. The next group of serial#'s would have abackground 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 makethe background color of identical serial#'s the same. Any input would be greatly appreciated.Thank you for your time,*Nick* Quote Link to comment https://forums.phpfreaks.com/topic/24010-color-coat-identical-rows/ Share on other sites More sharing options...
.josh Posted October 15, 2006 Share Posted October 15, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/24010-color-coat-identical-rows/#findComment-109122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.