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

Alternating Background Color of DB resultset

clintw
P: 10
Hi all,

I've been doing my head in trying to get this to work, but I keep running into a snag. Basically I have a database table with a list of events for the year, with fields for Month, Event Description, FullDate (used for sorting). When I input the result set into a HTML table, this works fine, alternating backgrounds colors for the individual rows is no problem - my problem comes in trying to alternate the background colors by Month (grouping common rows with one color), ie. each alternate month has different color to the one before. Only using two colors to differentiate.

Any suggestions how to get the logic right?

Thanks
Apr 23 '07 #1
Share this Question
Share on Google+
3 Replies


mwasif
Expert 100+
P: 801
Keep the month in a variable and compare this with every new month in the result. If the new month is equal to previous one don't change the color otherwise do and save the new month in the variable to compare in the next result.
Apr 23 '07 #2

clintw
P: 10
Keep the month in a variable and compare this with every new month in the result. If the new month is equal to previous one don't change the color otherwise do and save the new month in the variable to compare in the next result.
This was my understanding of the problem, except in practice it didnt work because it doesn't take the colors into account. I ended up the first entry of every month after the first one being in the alternate color. Theres a step I'm neglecting and I just can't think straight anymore.

Expand|Select|Wrap|Line Numbers
  1. // $row[0] holds the name of the month
  2.  
  3. if(empty($lastmonth)) $lastmonth = $row[0];
  4.  
  5. if ($lastmonth == $row[0]) 
  6. {
  7.        $color = "#D8DBFE";
  8. }
  9. else 
  10. {
  11.        $lastmonth = $row[0];
  12.        $color = "#A6ACFD";
  13. }
  14.  
Apr 23 '07 #3

clintw
P: 10
I actually got my own problem solved, but the actual code that got the job done is just too hideous to post on here. Guess I'll spend rest of my time trying to clean it up. Thanks for the reply mwasif. I thought more would have tried as well, but I figure this was a tricky one to solve.
Apr 24 '07 #4

Post your reply

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