473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Alternating Background Color of DB resultset

clintw
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
3 1552
mwasif
802 Expert 512MB
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
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
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

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

Similar topics

2
by: bettyann | last post by:
i am using templates via HTML_Template_IT to create a table from the results of a mysql query. i wanted to change the background image of alternating rows in the table. i thought i could do this...
1
by: Alistair Birch | last post by:
Hi I want rows of a table to appear in alternating background colours. Having looked around the web I can't find any solution apart from waiting for the next version of CSS, so I tried building...
1
by: Eirik Eldorsen | last post by:
I'm trying to set alternating bgcolor for a datalist with 2 columns. My problem is that its the alternating cell that get the bgcolor, not the row. Is it possible to set alternating color of rows?...
9
by: Max Weebler | last post by:
Hi, I have a datagrid built that has an alternating item style that sets the backcolor and ForeColor of its rows. I have 4 template columns. One of them has a LinkButton embedded in it to...
1
by: Steve Bottoms | last post by:
Hi, all! How does one prevent table cell background colors from alternating between grey and white? I've dropped a basic table control on an ASP.Net page (using VB.Net codebehind), and...
14
by: Tristan Miller | last post by:
Greetings. Is it possible with CSS to have an HTML <tablesuch that even-numbered <trrows have one background colour, and odd-numbered <trrows have another background colour? This makes wide...
3
by: Daniel Manes | last post by:
My DataGridView is set up like this: * Main row background color = white * Alternating row background color = light gray I also have a read-only (non-editable) column I want to show up as solid...
4
by: mike | last post by:
how can I change the font color for an alternating row where the column data is formatted as a link? setting a style in the stylesheet for a { color:white; }
1
by: Sachin | last post by:
Hi All, I am using ASP.NET Repeater Web Control. I want to use different stylesheets for alternating rows similar to DataGrid contorl. How can I do this? Thanks In Advance Sachin
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.