Alternating Colors
by
25 Feb 2002
Ok this is a pretty old 'trick' but I'm bored so here goes. This is how you can get the effect of switching colors, like posts in vBulletin and such. Code:
$bits = ''; $bgcounter = 0; $result=$DB_site->query("SELECT * FROM table"); while ($row=$DB_site->fetch_array($result) and ++$bgcounter) { $bgcolor = iif($bgcounter%2==0, '{firstaltcolor}', '{secondaltcolor}'); eval("\$bits .= \"".gettemplate("template")."\";"); } Then in the loop, we each time increment $bgcounter by one, so once it's an odd number and once it's even. And last, inside the loop we check every time wheter $bgcounter is even or odd. This is done using the modulus http://www.php.net/manual/en/language.operators.php. If it's even, we get {firstaltcolor} in $bgcolor. Otherwise, we put there {secondaltcolor}. Then all there's left to do is use $bgcolor in the template, and you will once get the first alternating color, and once the second. |
Similar Mods
[HowTo] Alternating colors for ONLY the postbit | vBulletin 2.x Full Releases |