alternate table rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thegenius
    New Member
    • Sep 2007
    • 7

    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
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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?

    Comment

    • thegenius
      New Member
      • Sep 2007
      • 7

      #3
      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

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        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:
        [code=php]
        <?php
        # Print the start of the table.
        echo "\n<table>" ;

        # Loop throught while $i is less than 10
        # each time incrementing $i by one.
        for($i = 0; $i < 10; $i++)
        {
        # $i % 2 divides the number $i by 2 and returns the rest (0 or 1)
        # which I then add one to, so this will alwasy be either 1 or 2
        $color = "color". ($i % 2 + 1);

        # Print a row into the table.
        echo "\n\t<tr><t d class=\"$color\ ">Row $i</td></tr>";
        }

        # Print the end of the table.
        echo "\n</table>";
        ?>[/code]
        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.

        Comment

        • thegenius
          New Member
          • Sep 2007
          • 7

          #5
          thank you for your reply,

          The code works perfectly ;)

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Moving to the HTML/CSS forum.

            Comment

            • drhowarddrfine
              Recognized Expert Expert
              • Sep 2006
              • 7434

              #7
              Or:
              .even{
              background-color:blue
              }
              .odd{
              background-color:yellow
              }

              <tr class="even">

              <tr class="odd">

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, TheGenius.

                Check out this article.

                Comment

                • drhowarddrfine
                  Recognized Expert Expert
                  • Sep 2006
                  • 7434

                  #9
                  I'm aware of that article but forgot about his css selector solution.

                  Comment

                  • drhowarddrfine
                    Recognized Expert Expert
                    • Sep 2006
                    • 7434

                    #10
                    Originally posted by pbmods
                    Heya, TheGenius.
                    Is that what they're calling me? I'll have to find this "they" person and shoot him.

                    Comment

                    • pbmods
                      Recognized Expert Expert
                      • Apr 2007
                      • 5821

                      #11
                      Originally posted by drhowarddrfine
                      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:)

                      Comment

                      • drhowarddrfine
                        Recognized Expert Expert
                        • Sep 2006
                        • 7434

                        #12
                        Does it pay more? .

                        Comment

                        • pbmods
                          Recognized Expert Expert
                          • Apr 2007
                          • 5821

                          #13
                          Originally posted by drhowarddrfine
                          Does it pay more? .
                          It pays 500% what you're getting for it now!!

                          Comment

                          Working...