views:

42

answers:

1

Hello, Trying to get this to function, randomly chooses 1 of the 3 color choices. Is rand only capable of generating numbers? or Numbers/letters in a series.

<div onclick="location.href='<?php the_permalink() ?>';"
style="cursor:pointer;background:#<?php echo rand (DDCA73, A0AA47, ADBAE1)?>;" 
class="post bg thickbox" id="thickbox post-<?php the_ID(); ?>">
+1  A: 

** rand or mt_rand randomize numbers not strings. Create an array, then randomize it's key selection.

<?php
    function random_color(){                   
            $colors_avail = array("DDCA73","A0AA47","ADBAE1");      
            $colors_count = count($colors_avail)-1; 
            $color_wheel = $colors_avail[mt_rand(0,$colors_count)];        
            echo $color_wheel;
     }
?>

<div onclick="location.href='<?php the_permalink() ?>';"
style="cursor:pointer;background:#<?php random_color(); ?>;" 
class="post bg thickbox" id="thickbox post-<?php the_ID(); ?>">
Codex73
I'm getting FATAL ERROR:Cannot redeclare random_color()Any ideas?
Jacob T.
@Jacob T. Sorry, I've corrected the code. See above.
Codex73