Monday, November 22, 2010

alternate row colors in PHP/HTML

SkyHi @ Monday, November 22, 2010
<?php
function doAlt($n) {
    if ($n % 2) {
        return 'alt';
    }
}
?>

for ($i = 0; $i <= 4; $i++)  {
    echo '
Row '.$i.'
'; }


$posts = array("Monday","Tuesday","Wednesday","Thursday","Friday","Satursday","Sunday");
$i = '';
foreach($posts as $post){
        echo '
'.$post.'
'; $i++; }


include_once('../smtp/includes/mysqli_connect.php');
$query = "SELECT username, password FROM mailbox";
if ($result = mysqli_query($dbc, $query)) {
        $i='';
        while($row = mysqli_fetch_assoc($result)) {
                echo '
'.$row['username'].$row['password'].'
'; $i++; } /* free result set */ mysqli_free_result($result); } /* close connection */ mysqli_close($dbc);



<style>
.row {
background-color:#000000;
color:#FFFFFF;
width:300px;
}

.rowalt {
background-color:#C0C0C0;
color:#FF0000;
width:300px;
}
</style>


REFERENCES
http://stackoverflow.com/questions/399137/easiest-way-to-alternate-row-colors-in-php-html
http://meetdustin.com/blog/articles/alternating-a-css-class-using-the-modulus-php-arithmetic-operator/
http://www.webdesign.org/web-programming/php/alternating-row-colors.12072.html