SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can PHP organise different colors for alternate columns in a table ?

    Hi all, been working on this for a while, but can't seem to get it solved. if you had a table of 5 columns, how would you ensure, using PHP only, that the 1st column was blue, the 2nd column white, 3rd blue, 4th white and the 5th one blue please ?

    The table comes from another source, so am not able to alter any of the code within the table.

    Any help very much appreciated.

    Dez.

  2. #2
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Adapt the example

    Code:
    $i = 0;
    while( your loop here ) {
    
      if ( $i % 2 == 0 ) echo 'blue';
      else echo 'white';
     ++$i;
    }
    David

  3. #3
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ClickHeRe View Post
    Adapt the example

    Code:
    $i = 0;
    while( your loop here ) {
    
      if ( $i % 2 == 0 ) echo 'blue';
      else echo 'white';
     ++$i;
    }
    Many thanks for the quick response David - it's appreciated.

    When you say adapt the code - I assume that I should be changing it somehow ?

    I just absolutely love the power of PHP, but am still learning

    Dez.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2005
    Location
    Sparks, NV, USA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll need to change the code to work with your code to get the color to work. This will just print out the words "blue" and "white". Depending on how your code is setup and what your constraints are, you may want to do something like select a particular CSS class and put that in place of the "blue" and "white" contained in the example code.

  5. #5
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sperlock View Post
    You'll need to change the code to work with your code to get the color to work. This will just print out the words "blue" and "white". Depending on how your code is setup and what your constraints are, you may want to do something like select a particular CSS class and put that in place of the "blue" and "white" contained in the example code.
    Many thanks Sperlock. Because the tables contents (from another source), are already predefined, I'm having some problems trying to switch around the colors ;-(

    There's quite a few of these in the table - <TD BGCOLOR="#FFFFFF" ALIGN="CENTER"> ;-(

    It would be good if there was some way of saying "when you see something like <TD BGCOLOR="#FFFFFF" ALIGN="CENTER">, please turn it into <TD>" ;-)

    Short of doing magic, I don't think there's any more we can do on this, unless anyone here knows differently.

    All the best.

    Dez.
    Last edited by Dez; Mar 17, 2007 at 04:55.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •