I’m currently working on creating a website with a blogging platform, and I want every other post container on the home page to alternate colours. Like light blue, then dark blue, light blue, dark blue, light blue, etc. I’m using a while loop to get 5 posts from the mysql database. Here is my code.
<?php
$sql = mysql_query("SELECT * FROM posts ORDER BY id DESC LIMIT 6");
$array = mysql_fetch_array($sql);
while ($array = mysql_fetch_array($sql)) {
//The php below this is the problem
$counter = 0;
$counter++;
$postcolour = WHAT DO I PUT HERE ? 'lightblue' : 'darkblue';
?>
<div class="postcontainer" style="background-color: <?php echo $postcolour; ?>;">
</div> <?php } ?>
Just use modulus two: