the function to switch values ie for alternating between 2 colors in table display

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monomaniac21

    the function to switch values ie for alternating between 2 colors in table display

    Hi all!

    What is the php function called which allows you to alternate between
    two values? I've completely forgotten it and my searches in php.net
    have not been fruitful!

    Kind regards

    Marc

  • monomaniac21

    #2
    Re: the function to switch values ie for alternating between 2 colors in table display

    it has something like this in it somehere:

    for($i=0; $i<10; $i++) {
    echo $i % 2 ? $catodd : $cateven;
    }



    monomaniac21 wrote:
    Hi all!
    >
    What is the php function called which allows you to alternate between
    two values? I've completely forgotten it and my searches in php.net
    have not been fruitful!
    >
    Kind regards
    >
    Marc

    Comment

    • Geoff Berrow

      #3
      Re: the function to switch values ie for alternating between 2 colors in table display

      Message-ID: <1152692807.376 022.27670@s13g2 000cwa.googlegr oups.comfrom
      monomaniac21 contained the following:
      >
      >What is the php function called which allows you to alternate between
      >two values? I've completely forgotten it and my searches in php.net
      >have not been fruitful!
      There is a function?

      I usually just do something like this

      $rowstyle=($cou nt%2!=1)?" style='backgrou nd-color:#ddd'":"
      style='backgrou nd-color:#fff'";
      $count++;

      for each table row.

      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • frothpoker

        #4
        Re: the function to switch values ie for alternating between 2 colors in table display


        I prefer

        $linestyle = 1

        While (criteria)
        {
        .......
        $lineclass = "lineclass" . $linestyle;
        <TR class = $lineclass><TD> </TD></TR>;

        $linestyle = 1 - $linestyle;
        }

        and set up two classes called lineclass0 and lineclass1

        personally I think it is easier to read and control.

        Comment

        • Chung Leong

          #5
          Re: the function to switch values ie for alternating between 2 colors in table display

          monomaniac21 wrote:
          it has something like this in it somehere:
          >
          for($i=0; $i<10; $i++) {
          echo $i % 2 ? $catodd : $cateven;
          }
          Just use an array:

          $class = array('blue', 'red');

          echo $class[$i%2];

          Comment

          Working...