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.
$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")."\";");
}
At first we initalize $bgcounter to 0, so we know exactly what comes first (first or second color).
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 operator (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. :)
thanks finally i can get that working
firefly you a genius I just did what I needed to do in seconds, I even amazed myself ;)
pardon the newbie question, but I just installed purchased and installed vbulletin yesterday and I want to install this hack.
In which module do I install this code?
thanks in advance and pardon my ignorance.
all in all, I got purchased the product and had the forum up and running in about 3 hours...
- jeff
This is not a hack. You file hacks in the Full Releases forum, this just a forum to share small tips with other hackers. :)
thanks
could you maybe give a bit of help on how to implement this please?