471,598 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,598 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 3137
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

Post your reply

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

Similar topics

1 post views Thread by jeffgeorge | last post: by
4 posts views Thread by sconeek | last post: by
6 posts views Thread by sconeek | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

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.