#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Greece
    Posts
    10
    Rep Power
    0
    Hallo,
    I want to create a Perl script that will read a few lines from a database and then it will create an HTML table. The problem:
    I need a function that will finds if a number is odd or even because I want to have defferent color to each line. Does anybody knows how to do that?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    15
    Use modula(%)-operator. If x%2 is 1 then odd . If x%2 is 0 then even. In Perl:

    if ($number%2==1) {
    # $number is odd
    }
    else {
    # $number is even
    }

    ------------------
    Good luck,
    Bas

    ------------------
    E-mail me at: b.vandermeijden@pecoma.nl
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    114
    Rep Power
    15
    I think you could do this in PERL, but this is PHP, i think it's a little cleaner than using an if-then construct.

    $rowColors=Array("#cccccc","#eeeeee");
    /*
    I think the PERL would be something like:
    @rowColor=("#cccccc","#eeeeee");
    and then you use "print" and not echo,
    right?
    */
    $index=0;
    echo "<table>";
    for ($i=0;$i<10;$i++)
    {
    echo "<tr bgcolor=".$rowColors[$index]."><td></td></tr>";
    $index=-($index)+1; // this makes it alternate
    }
    echo "</table>";

    Hope that helps.

    [This message has been edited by billyo (edited September 25, 2000).]
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Greece
    Posts
    10
    Rep Power
    0
    Hi again.
    THe second message looked more like perl (or C++ ). I tries both solutions. I was thinking that the % was PHP too, but it worked fine.
    So, I have to say thanks.
    Cheers,
    Peter

IMN logo majestic logo threadwatch logo seochat tools logo