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

    Join Date
    May 2000
    Location
    Denmark
    Posts
    53
    Rep Power
    14
    Hi!
    I got this crazy idea:
    On a page I got some headlines with some text between (all from a mySQL db). I would like to have each of those headlines in a different, random color from a group of predefined colors, e.g. one headline in red, one in green and one in blue, so that the color of each headline changes when reloading the page.
    Is it possible? I'm still pretty new i PHP and don't have the faintest idea of how to do it.

    Thanks.
    Ole, Denmark.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    33
    Rep Power
    14
    Why don't you define a group of colors like this in a separate include file or elsewhere:
    (Include ("colorgenerator.inc") :

    $ColorNumber = 7;
    $sec = Date(s);
    $Color = $sec % $ColorNumber;
    $Color +=1;
    if ($Color==1) {
    $FontString="#FF0066";
    }
    elseif ...
    Then put the variable where you want the color to be with <font color="<? $FontString ?>">.
    This will be functional enough if you have not many colors (better less than 10), and I guess you don't need more than 10, colors don't always go with each other.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    24
    Rep Power
    0
    What i would do is have an array of numbers, say like

    $colors[0] = "#000000"
    $colors[1] = "#000033"
    $colors[2] = "#000066"
    $colors[3] = "#000099"

    the get a random number between 0 and sizeOf($colors); then just say

    <font color="<? echo($colors[$rndNum]); ?>">Random Text</font>

    that way there wont be performance issuses that will be in the above code, do to having to check through a bunch of if/else statements.

Similar Threads

  1. How to change a listbox control item's font color?
    By gigabite in forum Visual Basic Programming
    Replies: 2
    Last Post: January 13th, 2004, 12:33 AM
  2. Runtime color and font change in ASP.NET
    By sameergupte in forum .Net Development
    Replies: 0
    Last Post: December 17th, 2003, 07:15 AM
  3. changing font color based on mysql query result
    By taterb in forum PHP Development
    Replies: 5
    Last Post: September 25th, 2003, 04:47 PM
  4. Trying to get roll-over to work with just changing font color
    By rllewisbu in forum HTML Programming
    Replies: 1
    Last Post: August 16th, 2003, 01:06 AM
  5. Netscape problem
    By MarioPro in forum HTML Programming
    Replies: 9
    Last Post: March 3rd, 2003, 02:10 PM

IMN logo majestic logo threadwatch logo seochat tools logo