473,412 Members | 3,343 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,412 software developers and data experts.

alternate table rows

hey everyone,
I'm transforming my site to be database driven website for better and faster modification since it uses HTML for the moment.
My quetion is,
I have a control panel where I can control the tables of the site, some sections, edit the css...
there is a section on my site where a table has to be created to display some info with specs for the user [hosting plans]

let's take this exmple
Plan Name
Space
Bandwidth
POP3
FTP
MySQL
...

now from my control panel, i want to add:
plan 1
1 Gb
yes / or image [tick]
yes / or image
no / or image [x]

the question is as shown in the title,
I want that every row of the table to be altered from the row coming after it
so the first row will be white, the second will be gray, it will get the colors from a css file.
and I want the table header to be color fixed differnet from the rows, i.e blue

any help would be really appreciated

thanks in advance
Sep 29 '07 #1
12 3318
Atli
5,058 Expert 4TB
Hi. Welcome to The Scripts!

So basically what you are trying to do is paint the background of every other row differently from the one above it? That is to say; odd row numbers one color and even numbers another?

If so then the first thing we need to know, what type of server-side script are you using? PHP? ASP? etc...
Are you perhaps planing on doing this in JavaScript?

And is there any particular reason why you posted this in a MySQL forum?
Sep 29 '07 #2
hey Atli,

this is what i want, even rows color is different than the odd ones.

I'm using PHP/MySQL

Is there any else method other than the javascript one ?

I posted in the MySQL forum for the reason shown below:

I'm transforming my site to be database driven website for better and faster modification since it uses HTML for the moment.
which i thought that the answer for my question, can be found here, where MySQL experts are


regards
Sep 29 '07 #3
Atli
5,058 Expert 4TB
OK I see.

In the much popular PHP/MySQL duo, the actual coding is done in PHP. MySQL is mostly just a data storage, the database which PHP uses to store data in.

So, to solve your problem, you would need a PHP code. Something similar to this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Print the start of the table.
  3. echo "\n<table>";
  4.  
  5. # Loop throught while $i is less than 10
  6. # each time incrementing $i by one.
  7. for($i = 0; $i < 10; $i++) 
  8. {
  9.   # $i % 2 divides the number $i by 2 and returns the rest (0 or 1)
  10.   # which I then add one to, so this will alwasy be either 1 or 2
  11.   $color = "color". ($i % 2 + 1);
  12.  
  13.   # Print a row into the table.
  14.   echo "\n\t<tr><td class=\"$color\">Row $i</td></tr>";
  15. }
  16.  
  17. # Print the end of the table.
  18. echo "\n</table>";
  19. ?>
Now this code assumes that there are CSS classes called "color1" and "color2" that contain the color.

You will obviously need to adapt this to your own code, but you can see where I am going with this.
Sep 29 '07 #4
thank you for your reply,

The code works perfectly ;)
Sep 29 '07 #5
pbmods
5,821 Expert 4TB
Moving to the HTML/CSS forum.
Sep 29 '07 #6
drhowarddrfine
7,435 Expert 4TB
Or:
.even{
background-color:blue
}
.odd{
background-color:yellow
}

<tr class="even">

<tr class="odd">
Sep 30 '07 #7
pbmods
5,821 Expert 4TB
Heya, TheGenius.

Check out this article.
Sep 30 '07 #8
drhowarddrfine
7,435 Expert 4TB
I'm aware of that article but forgot about his css selector solution.
Sep 30 '07 #9
drhowarddrfine
7,435 Expert 4TB
Heya, TheGenius.
Is that what they're calling me? I'll have to find this "they" person and shoot him.
Sep 30 '07 #10
pbmods
5,821 Expert 4TB
Is that what they're calling me? I'll have to find this "they" person and shoot him.
The OP's nick is 'thegenius', and I embellished it a bit with some fancy capitals.

But we all like to think of you as "theGenius". 0:)
Sep 30 '07 #11
drhowarddrfine
7,435 Expert 4TB
Does it pay more? .
Sep 30 '07 #12
pbmods
5,821 Expert 4TB
Does it pay more? .
It pays 500% what you're getting for it now!!
Sep 30 '07 #13

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

Similar topics

5
by: Matt | last post by:
I want to produce colors in alternate rows in the table. The following will produce blue color on every row. So my problem is to figure out to count the records. If it is odd record, then do <tr...
1
by: jeffgeorge | last post by:
Using a bit of code to produce alternate line shading in a report. Seems it should work for a form as well but no luck. Does anyone have any ideas what I need to change or if it is even possible...
4
by: sconeek | last post by:
Hi all, I am generating a html based table with multiple rows of data coming in real time from a postgres DB. The underlying technology is java based however the front end is html. now i am...
6
by: sconeek | last post by:
hi all, my java servlet code has a foreach loop which automatically generates a HTML table with x number of rows. now my problem is that I would like the rows to be alternating in colour so that...
4
by: Amy | last post by:
I need some help. I have this table with alternate row colors. Class gray and class white. I have javascript that do highlight when mouseover row ... and onclick to select row and highlight it...
0
by: samuel saravanan | last post by:
Hai To All , Could U Plz Tell Me Asp Coding To Create A Table But With Alternate Coloured Rows, And Also Tell Me Some Of Techniques To Positioning The Table At Right Place In A Web...
1
by: pradheepayyanar | last post by:
Dear All i have dynamic generation of <table> rt now i have done the <TR> with alternate colors which is a dynamic table. my requirement is that for every cumulative <tr> i need different color....
1
by: pixelnate | last post by:
I am trying to use a CSS class called "evens" to color the background of alternate rows of a dynamic table. The foreach statement is preventing the data from being displayed at all. If I take it out,...
5
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background...
18
by: JohnDriver | last post by:
Hi, I am happy to say that with your help, I have been performing good in Ajax. Thanks for helping me to start with. I have a small problem now. I am pulling records from database and passing...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.