473,789 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alternating Background Color of DB resultset

clintw
10 New Member
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 1568
mwasif
802 Recognized Expert Contributor
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 New Member
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 New Member
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
1759
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 by defining two different blocks in the template file and setting the current block based on ( $thisRowNum % 2 ). when the final table is displayed, all the "even" rows are displayed before all the "odd" rows. in other words, the rows are not...
1
4578
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 one myself, but I need some help to finish it. I use the getAttribute('rowIndex') to return the position of a row within the table and apply modulo 2 to return a 0 or 1 indicating an even or odd row number, from which I apply the alternating...
1
4679
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? Here is my code: <asp:DataList id=dlKommuner runat="server" Width="400px" RepeatColumns="2" CellPadding="3"> <AlternatingItemStyle Width="200px" CssClass="arow"> </AlternatingItemStyle>
9
2695
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 perform updates. All the styles that are set are being followed by all templated columns with the exception for the update column. The update column does set the BackColor appropriately but when setting its ForeColor the LinkButton's color is blue and...
1
1316
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 dynamically creating rows and cells. However, I can't seem to get the blasted thing to stop alternating the background colors on every other row! I've tried setting the cell.BackColor property, but the value is just getting ignored! Also tried on...
14
2298
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 tables easier to read. I would like this to work by applying a CSS class to only the <table> element. Applying two different classes to alternate <trelements is undesirable, as then it would be impossible to add, delete, or sort table rows...
3
3715
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 dark gray (i.e., no alternating row colors), but it shows up as alternating dark/light gray. Is there any way to get around this?
4
5689
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
3276
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
9663
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.